After upgrading to the new Microsoft.EntityFrameworkCore.SqlServer 1.1.2 package, I encountered an error while trying to create a DBContext:
A System.IO.FileLoadException event HResult = 0x80131040 has occurred
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 installed assembly manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) Source = Microsoft.EntityFrameworkCore StackTrace: at Microsoft.EntityFrameworkCore.DbContext..ctor (DbContextOptions options) in Services.Infrastructure.Data.SqlServerDbContext..ctor (DatabaseOptions databaseOptions) in C: \ SRCages b .Infrastructure \ Data \ SqlServerDbContext.cs: line 16 in Translations.Api.Data.TranslationsDbContext..ctor (DatabaseOptions databaseOptions) in C: \ SRC \ backend \ Modules \ Translations \ Translations.Api \ Data \ TranslationsDb Context.cs: line 16
My DbContext Base
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 . , .