Please see this post for the solution.
Ok, I finally figured it out. The: AppDomain.CurrentDomain.GetAssemblies() piece of my code sometimes does not
For me this error had to do with where I put my CreateMap<>()
call. I had put it in the static initializer for my DTO. When I moved the CreateMap<>()
call to somewhere less cute, everything worked fine.
If you use Mapper.AssertConfigurationIsValid();
you would get bit more detailed info:
Unmapped members were found. Review the types and members below. Add a custom mapping expression, ignore, add a custom resolver, or modify the source/destination type
In any case, you have to have mapped all properties of destination model. You were missing CityDTO and 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 you would need some additional mapping on City-CityDTO, as you did not specify them.