简体   繁体   中英

Error when trying to Map List using Automapper

I need to map IReadOnlyList<Person> to IReadOnlyList<PersonResponse> using Automapper .

IReadOnlyList<Person> personList = await _personRespository.getall();

var t = MyMapper.Mapper.Map<IReadOnlyList<PersonResponse>>(personList );

Mapping Class

CreateMap<IReadOnlyList<PersonResponse>, IReadOnlyList<Person>>().ReverseMap();

The error I get:

System.TypeLoadException: Method 'get_Item' in type 'Proxy_System.Collections.Generic.IReadOnlyList`1[[App.Application.Responses.PersonResponse, App.Application, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]] 34471389 ' from assembly 'AutoMapper.Proxies, Version=0.0.0.0, Culture=neutral, PublicKeyToken=be96cd2c38ef1005' does not have an implementation. at System.Reflection.Emit.TypeBuilder.CreateTypeNoLock() at System.Reflection.Emit.TypeBuilder.CreateTypeInfo()

Create an mapping between Person and PersonResponse , the concerned element types. Automapper would take care of collections themselves.

CreateMap<PersonResponse, Person>().ReverseMap();

You can read more Automapper and Collections here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM