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

Created on 16 May 2017  路  17Comments  路  Source: dotnet/efcore

I've updated to the new package version and 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=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

Steps to reproduce

```c#
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; }
}

using

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

Further technical details

EF Core version: 1.1.2
Database Provider: Microsoft.EntityFrameworkCore.SqlServer
Operating system: Windows 10 Creators Update
IDE: Visual Studio 2017 15.2

closed-question

Most helpful comment

@ajcvickers Why did you close the issue? Yes the SO answer helps me to fix it but it also says that it

might be resolved in the upcoming 15.3 update / 2.0 .net core CLI"

So, will it resolve? When? And why I should add that properties after update?

All 17 comments

Please see this SO question that help to solve the problem

@Marusyk From you comment it seems like the question has been answered, so closing. If you are still seeing an issue, then please re-open and include a project that reproduces what you are seeing.

@ajcvickers Why did you close the issue? Yes the SO answer helps me to fix it but it also says that it

might be resolved in the upcoming 15.3 update / 2.0 .net core CLI"

So, will it resolve? When? And why I should add that properties after update?

I have the same issue and the SO suggestion did not fix it for me. I'm trying VS 15.3 & core 2 preview 1.

Could you share your *.csproj files? Are you using packages.config? (Things work better with package references in your csproj)

Although we do our best to understand and diagnose these types of issues, there is little the EF team can do to fix them. They typically belong on repositories like dotnet/sdk, dotnet/project-system, Microsoft/vstest, Microsoft/msbuild, or NuGet/Home

EF Team Triage: Closing this issue as the requested additional details have not been provided and we have been unable to reproduce it.

BTW this is a canned response and may have info or details that do not directly apply to this particular issue. While we'd like to spend the time to uniquely address every incoming issue, we get a lot traffic on the EF projects and that is not practical. To ensure we maximize the time we have to work on fixing bugs, implementing new features, etc. we use canned responses for common triage decisions.

I have the same issue, and I am unable to solve it following the SO article.
I am getting so tired of these assembly-binding issues from you guys @ Microsoft.

The problem, as i see it, is you are rerferencing 1.1.0.0 from Entity Core, but your recent updates to all NuGet nown gathers 1.1.1.

Assembly redirect look like this:
<dependentAssembly> <assemblyIdentity name="Microsoft.Extensions.DependencyInjection.Abstractions" publicKeyToken="adb9793829ddae60" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-1.1.1.0" newVersion="1.1.1.0" /> </dependentAssembly>

I have had this problem so many times I shudder to count. I still haven't figured out exactly the cause. However, a few months ago I put together a sample seed project that mixes .net core (targeting 4.6.2) and regular class libraries that does not have this problem.

Recently, I was upgrading an older project to the new .csproj .net core project type. I ran into this error again when trying to run my integration tests. Unfortunately I can't remember exactly all the steps to fix it but I copied and pasted my own code (.csproj files only) and voila! This error dissappeared. Hope this helps someone.

I had a similar issue whereby I was trying to add migrations in a separate project...

Create a project with EF in it. Create a class library that references ef project. Add DbContextFactory in class library. Add references to netCLITool and EFCore.Tools package. Try add migrations on class library, will fail with error mentioned above. Fix for me was to add <OutputType>Exe</OutputType>.

Will attempt to create repro on Mon and new issue

I just got done struggling with the same issue. My scenario was that I was trying to get migrations working in a Docker container. I took the road suggested by a post in a SO thread that involved using the --verbose flag with dotnet ef database update and fishing out the dotnet exec ... ef.dll ... command that it generated behind the scenes. However, I hit the topical issue and it was not until I went on and compared the dotnet exec command generated by dotnet ef database update in the container to the same command generated by dotnet ef database update in my regular dev environment (which worked) that I noticed that the command used in the container lacked the --runtimeconfig argument that pointed to the service's *.runtimeconfig.json file. Adding that argument to the dotnet exec command solved the issue for me.

I hope I will help at least someone

My problem is:
I have ASP Net MVC 5 application which refers on .Core project. And this core project uses IHttpClient in some service. .Core project has a reference on Microsoft.Extensions.whatever.

For some reason compiler doesn't understand that that he needs to copy this .dll to bin folder.

So I just added this extention directly to my MVC project via NuGet.

And do not forget do do next thing: .AddHttpClient() when you register DI

I have this problem with an Azure Function, netcore 3.1 and the SO does not help.

Having a similar issue when updating from 2.2 to 3.1. Posted a SO question here. Seems like I have to manually add bindingRedirect for every single ones of the .NET libraries, which makes no sense. Surely there's a better way?

I just got this because of installing SignalR Client Preview
which have nothing to do with entity but It break. So I removed it and go back to the 3.1.4 version of SignalR and then every worked fine.
My Advice for you is to check all of your packages and recent packages see what causing it

Also seeing this issue with a template Azure functions project and netcore 3.1

[2020-10-20T01:38:20.534] testDetached: Could not load file or assembly 'Microsoft.Extensions.DependencyInjection.Abstractions, Version=5.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.
Value cannot be null. (Parameter 'provider')

Same error here, trying to preview .NET 5 with Entity Framework Core 5 RC and Azure Functions v3.

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <AzureFunctionsVersion>v3</AzureFunctionsVersion>
    <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
    <GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Detached.Mappers.EntityFramework" Version="5.0.0-rc.1.20451.13" />
    <PackageReference Include="Microsoft.AspNetCore" Version="2.2.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.1.0" />
    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.0-rc.2.20475.6" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="5.0.0-rc.2.20475.6">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="5.0.0-rc.2.20475.6" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.0-rc.2.20475.6" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="5.0.0-rc.2.20475.6">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>

    <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="5.0.0-rc.2.20475.5" />
    <PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="5.0.0-rc.2.20475.5" />
    <PackageReference Include="Microsoft.Extensions.Http" Version="5.0.0-rc.2.20475.5" />
    <PackageReference Include="Microsoft.Extensions.Logging.Console" Version="5.0.0-rc.2.20475.5" />
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.9" />
    <PackageReference Include="System.Data.SqlClient" Version="4.8.2" />
  </ItemGroup>
  <ItemGroup>
    <None Update="host.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="local.settings.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <CopyToPublishDirectory>Never</CopyToPublishDirectory>
    </None>
  </ItemGroup>
</Project>

This is my .csproj file, I also tried the old SO workaround, to no avail.
Is there anything I can do to fix this?

@vaibhavrmore1 why are you posting this here, I see no EF Core packages?

Was this page helpful?
0 / 5 - 0 ratings