我已经在我的项目中安装了以下 Nuget 包:
Automapper
AutoMapper.Extensions.Microsoft.DependencyInjection
我已将该行添加到
ConfigureServices
在 Startup.cs
.public void ConfigureServices(IServiceCollection services)
{
// Add framework services.
services.AddMvc();
// . . .
services.AddAutoMapper();
}
我仍然在
services.AddAutoMapper()
下看到一条红线.它说:The Call is ambiguous between the following methods or properties: ServiceCollectionExtensions.AddAutoMapper(IServiceCollection, params Assembly[]) and ServiceCollectionExtensions.AddAutoMapper(IServiceCollection, params Type[])
为什么会这样?我读过的所有 .NET Core 添加自动映射器指南都显示了这样做的方式。
最佳答案
我遇到了同样的问题,所以检查了 sourcecode and tests为指导。您似乎需要在要扫描的程序集中传递程序集或“标记类型”。我选择了以下作为我的 Profile
类与 Startup
在同一个程序集中类(class)。
services.AddAutoMapper(typeof(Startup));
关于.net - 尝试将 AutoMapper 添加到 .NetCore1.1 - 无法识别 services.AddAutoMapper(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42916182/