Is the Automapper broken now?
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?
Comments are currently closed for this discussion. You can start a new one.
2 Posted by Ryan on 20 Apr, 2010 10:52 PM
Here's the stack trace:
FluentNHibernate.Utils.Extensions.<>c__DisplayClass1
1.<In>b__0(T x) in d:\Builds\FluentNH\src\FluentNHibernate\Utils\Extensions.cs: line 11 System.Linq.Enumerable.Any[TSource](IEnumerable
1 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, IList
1 mappedProperties) in d:\Builds\FluentNH\src\FluentNHibernate\Automapping\AutoMapper.cs: line 139FluentNHibernate.Automapping.AutoMapper.MapEverythingInClass(ClassMappingBase mapping, Type entityType, IList
1 mappedProperties) in d:\Builds\FluentNH\src\FluentNHibernate\Automapping\AutoMapper.cs: line 129 FluentNHibernate.Automapping.AutoMapper.MapSubclass(IList
1 mappedProperties, ISubclassMapping subclass, AutoMapType inheritedClass) in d:\Builds\FluentNH\src\FluentNHibernate\Automapping\AutoMapper.cs: line 121FluentNHibernate.Automapping.AutoMapper.MapInheritanceTree(Type classType, ClassMappingBase mapping, IList
1 mappedProperties) in d:\Builds\FluentNH\src\FluentNHibernate\Automapping\AutoMapper.cs: line 108 FluentNHibernate.Automapping.AutoMapper.MergeMap(Type classType, ClassMappingBase mapping, IList
1 mappedProperties) in d:\Builds\FluentNH\src\FluentNHibernate\Automapping\AutoMapper.cs: line 57FluentNHibernate.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
3 Posted by Ryan on 20 Apr, 2010 11:04 PM
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.
Support Staff 4 Posted by James Gregory on 21 Apr, 2010 08:26 AM
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.
Support Staff 5 Posted by Paul Batum on 21 Apr, 2010 10:10 AM
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.
Paul Batum resolved this discussion on 21 Apr, 2010 10:10 AM.
Paul Batum re-opened this discussion on 21 Apr, 2010 10:10 AM
6 Posted by Ryan Younker on 21 Apr, 2010 12:03 PM
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
Support Staff 7 Posted by Paul Batum on 25 Apr, 2010 01:52 PM
Great, glad you've got a resolution Ryan.
Paul Batum resolved this discussion on 25 Apr, 2010 01:52 PM.