asp.net mvc 3 - Random "Missing type map configuration or unsupported mapping." Error in Automapper -
my entity:
/// <summary> /// get/set name of country /// </summary> public string countryname { get; set; } /// <summary> /// get/set international code of country /// </summary> public string countrycode { get; set; } /// <summary> /// get/set coordinate of country /// </summary> public coordinate countrycoordinate { get; set; } /// <summary> /// get/set cities of country /// </summary> public virtual icollection<city> cities { { if (_cities == null) { _cities = new hashset<city>(); } homecoming _cities; } private set { _cities = new hashset<city>(value); } }
my dto:
public guid id { get; set; } public string countryname { get; set; } public string countrycode { get; set; } public string lattitude { get; set; } public string longtitude { get; set; } public list<citydto> cities { get; set; }
my configuration
// country => countrydto var countrymappingexpression = mapper.createmap<country, countrydto>(); countrymappingexpression.formember(dto => dto.lattitude, mc => mc.mapfrom(e => e.countrycoordinate.lattitude)); countrymappingexpression.formember(dto => dto.longtitude, mc => mc.mapfrom(e => e.countrycoordinate.longtitude));
in global.asax application_start have:
bootstrapper.initialise();
and in bootstrapper have:
public static class bootstrapper { private static iunitycontainer _container; public static iunitycontainer current { { homecoming _container; } } public static void initialise() { var container = buildunitycontainer(); dependencyresolver.setresolver(new unitydependencyresolver(container)); } private static iunitycontainer buildunitycontainer() { _container = new unitycontainer(); _container.registertype(typeof(boundedcontextunitofwork), new perresolvelifetimemanager()); _container.registertype<icountryrepository, countryrepository>(); _container.registertype<itypeadapterfactory, automappertypeadapterfactory>(new containercontrolledlifetimemanager()); _container.registertype<icountryappservice, countryappservices>(); entityvalidatorfactory.setcurrent(new dataannotationsentityvalidatorfactory()); var typeadapterfactory = _container.resolve<itypeadapterfactory>(); typeadapterfactory.setadapter(typeadapterfactory); homecoming _container; } }
where adapter is:
public class automappertypeadapter : itypeadapter { public ttarget adapt<tsource, ttarget>(tsource source) tsource : class ttarget : class, new() { homecoming mapper.map<tsource, ttarget>(source); } public ttarget adapt<ttarget>(object source) ttarget : class, new() { homecoming mapper.map<ttarget>(source); } }
and adapterfactory is:
public automappertypeadapterfactory() { //scan assemblies find auto mapper profile var profiles = appdomain.currentdomain .getassemblies() .selectmany(a => a.gettypes()) .where(t => t.basetype == typeof(profile)); mapper.initialize(cfg => { foreach (var item in profiles) { if (item.fullname != "automapper.selfprofiler`2") cfg.addprofile(activator.createinstance(item) profile); } }); }
so randomly "missing type map configuration or unsupported mapping." error pointing:
public ttarget adapt<ttarget>(object source) ttarget : class, new() { homecoming mapper.map<ttarget>(source); }
while error occurs randomly hard debug , see happens. have searched lot no proper solution.
the error goes like:
missing type map configuration or unsupported mapping.
mapping types: country -> countrydto myapp.domain.boundedcontext.country -> myapp.application.boundedcontext.countrydto
destination path: list`1[0]
source value: myapp.domain.boundedcontext.country
my project mvc 3 project automapper 2.2 , unity ioc..
i appreciate idea, advice or solution , answers.
if utilize mapper.assertconfigurationisvalid();
bit more detailed info:
unmapped members found. review types , members below. add together custom mapping expression, ignore, add together custom resolver, or modify source/destination type
in case, have have mapped properties of destination model. missing citydto , id. here:
mapper.createmap<city, citydto>(); mapper.createmap<country, countrydto>() .formember(dto => dto.id, options => options.ignore()) .formember(dto => dto.longtitude, mc => mc.mapfrom(e => e.countrycoordinate.longtitude)) .formember(dto => dto.lattitude, mc => mc.mapfrom(e => e.countrycoordinate.lattitude));
maybe need additional mapping on city-citydto, did not specify them.
asp.net-mvc-3 unity-container automapper-2
No comments:
Post a Comment