Random “Missing type map configuration or unsupported mapping.” Error in Automapper

筅森魡賤 提交于 2019-12-02 09:37:35

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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!