When using AutoMapper I get the following error
Method 'GetEnumerator' in type 'Proxy' from assembly 'AutoMapper.Proxies, Version=0.0.0.0, Culture=neutral, PublicKeyToken=be96cd2c38ef1005' does not have an implementation.
In my repository I have a private method
private IMapper GetMapper()
{
var config = new MapperConfiguration(cfg => {
cfg.CreateMap<MyClass, PersistenceModels.MyClass>();
cfg.CreateMap<IEnumerable<PersistenceModels.MyClass>, IEnumerable<MyClass>>();
});
return new Mapper(config);
}
And then I use this as follows
var mapper = GetMapper();
var userInfo = mapper.Map<IEnumerable<PersistenceModels.MyClass>, IEnumerable<MyClass>>(userInfoRaw);
The MyClass
types are identical and have an IEnumerable
property
public IEnumerable<string> ImageUris { get; set; }
Any ideas how to solve this?
Edit
I am not mapping types defined by interface, I am mapping collections of concrete types, hence the IEnumerable
interface.
The solution was not to use IEnumerable
when creating maps, only when using the map.
So, in the configuration I changed from
cfg.CreateMap<IEnumerable<PersistenceModels.MyClass>, IEnumerable<MyClass>>();
to
cfg.CreateMap<PersistenceModels.MyClass, MyClass>();
and everything worked.
I hit the same problem. I guess AutoMapper wants to be told which implementation of IEnumerable to use for the target, so the following worked for me.
cfg.CreateMap<IEnumerable<PersistenceModels.MyClass>, List<MyClass>>();
^^^^
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With