TypeLoadException 使用具有 ASP.NET Core Identity 的 PostgreSQL

TypeLoadException using PostgreSQL with ASP.NET Core Identity

我正在尝试使用 PostgreSQL 作为 ASP.NET Core 1.0 Visual Studio 2015 项目中安装 VS2015 Update 3 和 Core 1.0 版本后的用户身份验证数据存储。

步骤:

  1. 新建 "ASP.NET Core Web Application (.NET Framework)" 项目。

  2. 添加 NuGet 包 "Npgsql" v3.1.4 和 "Npgsql.EntityFrameworkCore.PostgreSQL" v1.0.0-rc2-release1

  3. 修改Startup.cs中的ConfigureServices()如下:

    public void ConfigureServices(IServiceCollection services)
    {
        // Add framework services.
        services.AddEntityFrameworkNpgsql()
            .AddDbContext<ApplicationDbContext>(options =>
            options.UseNpgsql(Configuration.GetConnectionString("DefaultConnection")));
    
        services.AddIdentity<ApplicationUser, IdentityRole>()
            .AddEntityFrameworkStores<ApplicationDbContext>()
            .AddDefaultTokenProviders();
    
        services.AddMvc();
    
        // Add application services.
        services.AddTransient<IEmailSender, AuthMessageSender>();
        services.AddTransient<ISmsSender, AuthMessageSender>();
    }
    
  4. 运行

  5. 调用 AddDbContext() 时抛出异常:

An exception of type 'System.TypeLoadException' occurred in MyApp.exe but was not handled in user code

Additional information: Could not load type 'Microsoft.Extensions.DependencyInjection.Extensions.ServiceCollectionExtensions' from assembly 'Microsoft.Extensions.DependencyInjection.Abstractions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.

我认为这是一个兼容性问题,很快将在 Npgsql.EntityFrameworkCore.PostgreSQL 中解决,但我想确认这一点并确定是否有解决方法。

更新: This has been fixed.

这是 github 上的 known issue,很快就会修复。

6/29/2016

FYI 3.1.5 is out, targeting .NET Core RTM. The EFCore provider isn't out yet, that will take another day or two.