i have project running several months in same nh configuration opened today on clean installation of windows (vs 2015 rc installed, .net 4.6 rc installed, project targeting .net 4.5)
in building of nh session factory when these lines called:
var mapper = new automapper(); var mapping = mapper.compilemappingfor(typeof(entity).assembly.gettypes()); conf.addmapping(mapping); the last row throws exception: could not compile mapping document: mapping_by_code innerexception cannot extend unmapped class: [my_namespace].[my_entity_name]. when iterate through mapping, can see there object name [my_entity_name] , seems ok. object in collection after objects extends object (i'm not sure if can problem or order doesn't matter).
on other computer (other workstation, ci server, production , dev environment) didn't notice error, suppose can caused installed .net 4.6, machine .net 4.6. if understand correctly when .net 4.6 installed projects targeting .net 4.5 running in .net 4.6 runtime. tried run in vs 2013, no change... checking .net 4.6rc changelog didn't find cause error. suggestions?
update: checked on .net 4.5 machine order of items in mapping collection , in correct order (dependent subclass after parent subclass), seems order of types returned gettypes() (no ordering guaranteed) coincidentally working in .net 4.5, not working in .net 4.6 because compilemappingfor not reorder mappings of same type (here have dependency subclass -> subclass).
yes, reason order of assembly.gettypes() different in .net 4.5 , .net 4.6. coincidence order produced .net 4.5 working... modified following piece of code , works.
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 replaced partialorderby, can find implementation here - topological sorting using linq. makes topological sort instead of regular sort - have there objects not comparable (last return 0 in comparer) , general orderby can produce wrong results.
Comments
Post a Comment