Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Method 'GetEnumerator' in type Proxy<IEnumerable> does not have implementation

Tags:

automapper

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.

like image 802
nomad Avatar asked Sep 10 '16 20:09

nomad


2 Answers

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.

like image 98
nomad Avatar answered Nov 08 '22 00:11

nomad


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>>();
                                                      ^^^^
like image 9
x5657 Avatar answered Nov 08 '22 02:11

x5657