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

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

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

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 9
  • Comments: 18 (7 by maintainers)

Most upvoted comments

@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.

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.

@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?

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

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

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 have the same issue and the SO suggestion did not fix it for me. I’m trying VS 15.3 & core 2 preview 1.

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 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.