.net - 尝试将 AutoMapper 添加到 .NetCore1.1 - 无法识别 services.AddAutoMapper()

标签 .net asp.net-core asp.net-core-mvc automapper .net-core

我已经在我的项目中安装了以下 Nuget 包:

  • Automapper
  • AutoMapper.Extensions.Microsoft.DependencyInjection

  • 我已将该行添加到 ConfigureServicesStartup.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/

    相关文章:

    c# - dotnet core 3.0在vs中打开解决方案时无法找到dotnetcore sdk

    asp.net-core - 在 dotnet core 2.0 中实现自定义 key 存储库

    java - ASP.net 和 java 应用程序的单点登录

    c# - 通用存储库的依赖注入(inject)

    c# - 通过 ref 传入对象

    asp.net-core - 我可以安全地删除对 .pdb 文件的引用吗?

    asp.net-core-mvc - 类型 'IdentityRole' 在未引用的程序集中定义

    asp.net-core-mvc - .NET CLI 如何在 Linux 上发布后运行应用程序

    .net - SQL Server OLAP 多维数据集(教程)

    c# - 数组是否实现了 IEnumerable<T>?