Is the Automapper broken now?

Original Post Ryan's Avatar

Ryan

20 Apr, 2010 10:30 PM via web

I've upgraded to the most current build, so that I could upgrade the version of NHIbernate I was using, and it seems to have broken the automapper. I had to modify a couple of conventions so that it would build, and now I'm getting null reference exceptions when trying to spin up the session factory. If I set a break in the code where the Automapper is loading the types, it doesn't actually discover any types. Any ideas?

  1. 2 Posted by Ryan on 20 Apr, 2010 10:52 PM

    Ryan's Avatar

    Here's the stack trace:
    FluentNHibernate.Utils.Extensions.<>c__DisplayClass11.<In>b__0(T x) in d:\Builds\FluentNH\src\FluentNHibernate\Utils\Extensions.cs: line 11 System.Linq.Enumerable.Any[TSource](IEnumerable1 source, Func2 predicate) FluentNHibernate.Utils.Extensions.In[T](T instance, T[] expected) in d:\Builds\FluentNH\src\FluentNHibernate\Utils\Extensions.cs: line 11 FluentNHibernate.Automapping.AutoEntityCollection.MapsProperty(Member property) in d:\Builds\FluentNH\src\FluentNHibernate\Automapping\AutoEntityCollection.cs: line 23 FluentNHibernate.Automapping.AutoMapOneToMany.MapsProperty(Member property) in d:\Builds\FluentNH\src\FluentNHibernate\Automapping\AutoMapOneToMany.cs: line 18 FluentNHibernate.Automapping.AutoMapper.TryToMapProperty(ClassMappingBase mapping, Member property, IList1 mappedProperties) in d:\Builds\FluentNH\src\FluentNHibernate\Automapping\AutoMapper.cs: line 139
    FluentNHibernate.Automapping.AutoMapper.MapEverythingInClass(ClassMappingBase mapping, Type entityType, IList1 mappedProperties) in d:\Builds\FluentNH\src\FluentNHibernate\Automapping\AutoMapper.cs: line 129 FluentNHibernate.Automapping.AutoMapper.MapSubclass(IList1 mappedProperties, ISubclassMapping subclass, AutoMapType inheritedClass) in d:\Builds\FluentNH\src\FluentNHibernate\Automapping\AutoMapper.cs: line 121
    FluentNHibernate.Automapping.AutoMapper.MapInheritanceTree(Type classType, ClassMappingBase mapping, IList1 mappedProperties) in d:\Builds\FluentNH\src\FluentNHibernate\Automapping\AutoMapper.cs: line 108 FluentNHibernate.Automapping.AutoMapper.MergeMap(Type classType, ClassMappingBase mapping, IList1 mappedProperties) in d:\Builds\FluentNH\src\FluentNHibernate\Automapping\AutoMapper.cs: line 57
    FluentNHibernate.Automapping.AutoMapper.Map(Type classType, List`1 types) in d:\Builds\FluentNH\src\FluentNHibernate\Automapping\AutoMapper.cs: line 161
    FluentNHibernate.Automapping.AutoPersistenceModel.AddMapping(Type type) in d:\Builds\FluentNH\src\FluentNHibernate\Automapping\AutoPersistenceModel.cs: line 145
    FluentNHibernate.Automapping.AutoPersistenceModel.CompileMappings() in d:\Builds\FluentNH\src\FluentNHibernate\Automapping\AutoPersistenceModel.cs: line 119
    FluentNHibernate.Automapping.AutoPersistenceModel.BuildMappings() in d:\Builds\FluentNH\src\FluentNHibernate\Automapping\AutoPersistenceModel.cs: line 85

  2. 3 Posted by Ryan on 20 Apr, 2010 11:04 PM

    Ryan's Avatar

    Sorry to keep chiming in on my own issue, but it looks like the newer version of the code is assuming every single type is going to be contained in a namespace. While this would be ideal, it's not necessarily the case. I have some legacy code that has some enumerations that don't live inside a namespace. This looks like what is causing the exception.

  3. Support Staff 4 Posted by James Gregory on 21 Apr, 2010 08:26 AM

    James Gregory's Avatar

    I'm away right now, so can't do any bug fixes. If you're feeling daring,
    fork us on github and send me a pull request - I'll apply it when I get
    back.

  4. Support Staff 5 Posted by Paul Batum on 21 Apr, 2010 10:10 AM

    Paul Batum's Avatar

    I think I've found the relevant line and fixed it. Ryan you can get the fixed version from my dev branch which is here:

    http://github.com/paulbatum/fluent-nhibernate/tree/dev

    Can you confirm that the issue is resolved? If not, it would be great if you could provide more info or a test fixture that demonstrates the issue.

  5. Paul Batum resolved this discussion on 21 Apr, 2010 10:10 AM.

  6. Paul Batum re-opened this discussion on 21 Apr, 2010 10:10 AM

  7. 6 Posted by Ryan Younker on 21 Apr, 2010 12:03 PM

    Ryan Younker's Avatar

    Hi Paul,
    Thanks for the reply. I actually worked around it so I could move on. I
    just stuck the Enums into a namespace. Wound up modifying about 100 files,
    and don't have time to go back at the moment. You should be able to
    recreate and test the issue pretty easily. Otherwise, I can possibly get
    back to it later in the week.

    I have the following convention set up for enums:

    public class EnumConvention : IPropertyConvention,
    IPropertyConventionAcceptance
        {
            #region IConventionAcceptance<IPropertyInspector> Members

            public void Accept(IAcceptanceCriteria<IPropertyInspector> criteria)
            {
                criteria.Expect(x => (x.Property.PropertyType.IsEnum
                    || (x.Property.PropertyType.IsGenericType &&
    x.Property.PropertyType.GetGenericTypeDefinition() == typeof(Nullable<>) &&
    x.Property.PropertyType.GetGenericArguments()[0].IsEnum)));
            }

            #endregion

            #region IConvention<IPropertyInspector,IPropertyInstance> Members

            public void Apply(IPropertyInstance instance)
            {
                instance.CustomType(instance.Property.PropertyType);
            }

            #endregion
        }

    So, using that convention and a property that's an enum that's not inside a
    namespace declaration, you should see it with the old code, but not with the
    new code.

    Let me know if I can be of any assistance.

    Thanks again for getting back to me so quickly.

    I love the project, and appreciate all your hard work.

    Regards,
    Ryan Younker

  8. Support Staff 7 Posted by Paul Batum on 25 Apr, 2010 01:52 PM

    Paul Batum's Avatar

    Great, glad you've got a resolution Ryan.

  9. Paul Batum resolved this discussion on 25 Apr, 2010 01:52 PM.

Comments are currently closed for this discussion. You can start a new one.

Recent Discussions

05 Jul, 2010 10:29 PM
05 Jul, 2010 12:45 PM
05 Jul, 2010 12:42 PM
05 Jul, 2010 12:17 PM
05 Jul, 2010 12:12 PM

 

03 Jul, 2010 12:26 AM
02 Jul, 2010 02:17 PM
02 Jul, 2010 08:18 AM
02 Jul, 2010 12:20 AM
01 Jul, 2010 10:14 PM