對於我的MVC項目工作後,我升級我的NuGet包,並從 https://www.nuget.org/packages/AutoMapper/AutoMapper不升級5.1.1
它說的IList支持作爲映射源得到了最新版本AutoMapper的; https://github.com/AutoMapper/AutoMapper/wiki/Lists-and-arrays
它使用舊版本,我只更新了我的配置部分。
配置如下;
public class MvcApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
AutoMapperConfig.RegisterMappings();
}
}
public static void RegisterMappings()
{
Mapper.Initialize(cfg =>
{
cfg.CreateMap<RssNewDto, RssNewViewModel>();
});
}
// where I am trying to resolve
[HttpGet]
public IList<RssNewViewModel> ReadList()
{
// EXCEPTION
IList<RssNewViewModel> items2 = AutoMapper.Mapper.Map<IList<RssNewDto>, IList<RssNewViewModel>>(items);
return items2;
}
ERROR: AutoMapper.AutoMapperMappingException occurred
HResult=-2146233088 Message=Error mapping types. InnerException: HResult=-2146233088 Message=Missing type map configuration or unsupported mapping.
我失去了對配置的東西嗎?
什麼是其餘的例外信息?它應該包括缺少的類型信息。 –
@JimmyBogard在我調用MapperConfiguration.AssertConfigurationIsValid方法後,它向我展示了所有丟失的配置錯誤。我相信這個應該在Initialize方法之後被內部調用。由於人們可能忘記調用這個方法,可能會有無效的配置映射器,它會在運行時咬他們。 –
哦,是的,我看到很多人這樣做。我不確定是否在製作,但我認爲我在那裏是少數。 –