gpt4 book ai didi

c# - 无法加载文件或程序集 Microsoft.Extensions.DependencyInjection.Abstractions,版本 = 1.1.0.0

转载 作者:IT王子 更新时间:2023-10-29 04:24:12 25 4
gpt4 key购买 nike

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

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:\src\backend\Packages\Services.Infrastructure\Data\SqlServerDbContext.cs:line 16 at Translations.Api.Data.TranslationsDbContext..ctor(DatabaseOptions databaseOptions) in C:\src\backend\Modules\Translations\Translations.Api\Data\TranslationsDbContext.cs:line 16

我的基础 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; }
}

创建上下文实例的地方

 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 之前一切正常。请帮助解决问题。

最佳答案

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

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

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

关于c# - 无法加载文件或程序集 Microsoft.Extensions.DependencyInjection.Abstractions,版本 = 1.1.0.0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43995432/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com