NHibernate code in .NET 4.6 throws "Unable to extend unlabeled class"

I have a project that has been working for several months in the same NH configuration that I opened today on a clean install of Windows (VS 2015 RC is installed, .NET 4.6 RC is also installed, but the project targets .NET 4.5)

When creating an NH factory session when these lines are called:

var mapper = new AutoMapper();
var mapping = mapper.CompileMappingFor(typeof(Entity).Assembly.GetTypes());
conf.AddMapping(mapping);

the last line throws an exception: Could not compile the mapping document: mapping_by_codewith InnerException Cannot extend unmapped class: [my_namespace].[my_entity_name]. When I repeat through mapping, I see an object with a name [my_entity_name], and everything looks fine. Only this object is in the collection after the objects that extend this object (I'm not sure if this could be a problem or the order doesn't matter).

On any other computer (another workstation, CI server, production and development environments), we did not notice this error, I believe that this may be caused by installing .NET 4.6, this is the only computer with .NET 4.6. If I understood correctly when .NET 4.6 is installed, all projects oriented to .NET 4.5 work in the .NET 4.6 runtime. I also tried to run it in VS 2013, but with no changes ... I also checked the .NET 4.6RC change log, but I did not find anything that could cause this error. Any suggestions?


: .NET 4.5 mapping ( ), , , GetTypes() ( ), .NET 4.5, .NET 4.6, CompileMappingFor ( SubClass → SubClass).

+4
1

, , Assembly.GetTypes() .NET 4.5 .NET 4.6. , , .NET 4.5, ... , .

var types = typeof (Entity).Assembly.GetTypes().Where(t => !t.IsInterface).PartialOrderBy(x => x, new EntityTypeComparer());
var mapping = mapper.CompileMappingFor(types);    

public class EntityTypeComparer : IComparer<Type>
{
    public int Compare(Type x, Type y)
    {           
        if (x == y)
            return 0;
        if (x.IsAssignableFrom(y) || (!x.IsAssignableTo<Entity>() && y.IsAssignableTo<Entity>()))
            return -1;
        if (y.IsAssignableFrom(x) || (!y.IsAssignableTo<Entity>() && x.IsAssignableTo<Entity>()))
            return 1;
        return 0;
    }
}      

EDIT: OrderBy PartialOrderBy, - LINQ. - , ( 0 ), OrderBy .

+4

All Articles