尝试使用 Automapper 映射列表时出错

Error when trying to Map List using Automapper

我需要使用 AutomapperIReadOnlyList<Person> 映射到 IReadOnlyList<PersonResponse>

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

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

映射Class

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

我得到的错误:

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()

在相关元素类型 PersonPersonResponse 之间创建映射。 Automapper 会自己处理集合。

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

您可以阅读更多 Automapper 和 Collections here