无法加载文件或程序集 Microsoft.Extensions.DependencyInjection.Abstractions, Version=1.1.0.0 [英] Could not load file or assembly Microsoft.Extensions.DependencyInjection.Abstractions, Version=1.1.0.0

查看:32
本文介绍了无法加载文件或程序集 Microsoft.Extensions.DependencyInjection.Abstractions, Version=1.1.0.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更新到新包 Microsoft.EntityFrameworkCore.SqlServer 1.1.2 后,我在尝试创建 DBContext 时出错:

After update to the new package Microsoft.EntityFrameworkCore.SqlServer 1.1.2 I got error when try to create DBContext:

发生System.IO.FileLoadException HResult=0x80131040
消息=无法加载文件或程序集'Microsoft.Extensions.DependencyInjection.Abstractions,版本=1.1.0.0,文化=中性,PublicKeyToken=adb9793829ddae60' 或它的依赖项之一.定位的程序集的清单定义与程序集引用不匹配.(HRESULT 的例外:0x80131040)来源=Microsoft.EntityFrameworkCore StackTrace:在Microsoft.EntityFrameworkCore.DbContext..ctor(DbContextOptions选项)在Services.Infrastructure.Data.SqlServerDbContext..ctor(DatabaseOptions数据库选项)中C:srcackendPackagesServices.InfrastructureDataSqlServerDbContext.cs:line16 点Translations.Api.Data.TranslationsDbContext..ctor(DatabaseOptions数据库选项)中C:srcackendModulesTranslationsTranslations.ApiDataTranslationsDbContext.cs:line16

System.IO.FileLoadException occurred HResult=0x80131040
Message=Could not load file or assembly 'Microsoft.Extensions.DependencyInjection.Abstractions, Version=1.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) Source=Microsoft.EntityFrameworkCore StackTrace: at Microsoft.EntityFrameworkCore.DbContext..ctor(DbContextOptions options) at Services.Infrastructure.Data.SqlServerDbContext..ctor(DatabaseOptions databaseOptions) in C:srcackendPackagesServices.InfrastructureDataSqlServerDbContext.cs:line 16 at Translations.Api.Data.TranslationsDbContext..ctor(DatabaseOptions databaseOptions) in C:srcackendModulesTranslationsTranslations.ApiDataTranslationsDbContext.cs:line 16

我的基础 DbContext

My base DbContext

public class SqlServerDbContext : DbContext
{
    private readonly DatabaseOptions _databaseOptions;

    protected SqlServerDbContext(DatabaseOptions databaseOptions)
    {
        if (string.IsNullOrEmpty(databaseOptions.ConnectionString))
            throw new Exception("Database connection string is missed.");

        _databaseOptions = databaseOptions;
    }

    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
    {
        optionsBuilder.UseSqlServer(_databaseOptions.ConnectionString);
    }
}

我使用的数据库选项

public class DatabaseOptions
{
    public string ConnectionString { get; set; }
}

我创建上下文实例的地方

Place where I create instance of context

 var dbOptions = new DatabaseOptions { ConnectionString = _connectionString };
 DbContext = (TContext) Activator.CreateInstance(typeof(TContext), dbOptions);
// where TContext is derived class from SqlServerDbContext

我所有的包都更新了.Visual Studio 2017 15.2 (26430.6).在升级到 1.1.2 之前一切正常.请帮助解决问题.

All my packages are updated. Visual Studio 2017 15.2 (26430.6). Before upgrade to 1.1.2 everything works fine. Please help to solve the problem.

推荐答案

由于您在 .net 框架库中使用该项目,因此自动生成的绑定重定向存在问题(可能会在即将发布的 15.3 更新/2.0 .net 核心 CLI).要解决此问题,请将其添加到您的 cpsroj 文件中(最好在 .targets 文件的任何 <Import> 元素之前):

Since you're using the project in a .net framework library, there's an issue with auto-generated binding redirects (might be resolved in the upcoming 15.3 update / 2.0 .net core CLI). To work around it, add this in your cpsroj file (preferably before any <Import> element for a .targets file if present):

<PropertyGroup>
  <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
  <GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
</PropertyGroup>

这应该会强制 MSBuild 创建/更新包含必要绑定重定向的 YourProject.dll.config 文件.

This should force MSBuild to create / update a YourProject.dll.config file containing the necessary binding redirects.

这篇关于无法加载文件或程序集 Microsoft.Extensions.DependencyInjection.Abstractions, Version=1.1.0.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆