Reputation: 23052
For my MVC project, I upgraded my nuget packages and got latest version of AutoMapper from https://www.nuget.org/packages/AutoMapper/
It says IList is supported as mapping source; https://github.com/AutoMapper/AutoMapper/wiki/Lists-and-arrays
It was working with older version and I only updated my configuration section.
Configuration is as below;
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.
Am I missing something on configuration?
Upvotes: 0
Views: 576
Reputation: 11474
Your RegisterMappings
method is only creating a map from the RssNewDto
to the RssNewViewModel
, not from an IList<RssNewDto>
to IList<RssNewViewModel>
.
You could do this items.Select(item => AutoMapper.Mapper.Map<RssNewViewModel>(item)).ToList();
Upvotes: 0