Could not load file or assembly Microsoft.Extensions.DependencyInjection.Abstractions, Version=


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

System.IO.FileLoadException occurred HResult=0x80131040
Message=Could not load file or assembly 'Microsoft.Extensions.DependencyInjection.Abstractions, Version=, 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

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)

Database options that I use

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

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.

asked on Stack Overflow May 16, 2017 by Robert N. Dean

3 Answers


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):


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

answered on Stack Overflow May 16, 2017 by Martin Ullrich

I Googled my exception below, and it brought me to this stakoverflow post.

System.IO.FileNotFoundException: 'Could not load file or assembly 'Microsoft.Extensions.OptionsModel, Version=, Culture=neutral, PublicKeyToken=adb9793829ddae60' or one of its dependencies. The system cannot find the file specified.'

I had the relevant Binding Redirects but if I Delete all bin/obj folders it worked fine afterwards.

answered on Stack Overflow Nov 30, 2019 by metoyou

For me, what did it was to downgrade all the packages support .Net Standard to 2.2.0 from 3.x.x i guess the 3.x packages relevant to a different version of .Net standard which does not support ,net framework.

answered on Stack Overflow Jun 22, 2020 by Yosi Golan

User contributions licensed under CC BY-SA 3.0