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

前端 未结 2 1390
梦如初夏
梦如初夏 2021-01-26 09:47

Please see this post for the solution.

Ok, I finally figured it out. The: AppDomain.CurrentDomain.GetAssemblies() piece of my code sometimes does not

2条回答
  •  爱一瞬间的悲伤
    2021-01-26 10:29

    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();
    
    Mapper.CreateMap()
        .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.

提交回复
热议问题