Cannot load file or asembly 'Microsoft.Extensions.DependencyInjection.Abstractions'

0

I an old program, which uses Entity Framework Core 2.2.6 to access a MS-SQL database. Now I would like to add some tests to this program, which I would prefer to do using the InMemory package for EFCore.

I have a very simple method for getting data, which works in the actual program, but when I try to call it with an InMemory database, I get the following error:

System.IO.FileLoadException : Could not load file or assembly 'Microsoft.Extensions.DependencyInjection.Abstractions, Version=3.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) ----> System.IO.FileLoadException : Could not load file or assembly 'Microsoft.Extensions.DependencyInjection.Abstractions, Version=2.2.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)

Now it seems to expect Microsoft.Extensions.DependencyInjection.Abstractions version 3.1.0. However, I never asked it to install that. In fact I am trying to keep all EFCore versions <=2.2.6, as the program is created in the .NET Framework. The only difference I can find is that my test assembly seems to use the app.config file for package configuration, whereas my remaining assemblies are using a file called packages.config. This is not something I have done intentionally, it just autoconfigured it, when I was installing Nuget packages. Here is the difference between the content of the two:

app.config

<dependentAssembly>
  <assemblyIdentity name="Microsoft.Extensions.DependencyInjection.Abstractions" publicKeyToken="adb9793829ddae60" culture="neutral"/>
  <bindingRedirect oldVersion="0.0.0.0-3.1.0.0" newVersion="3.1.0.0"/>
</dependentAssembly> 

packages.config

<package id="Microsoft.Extensions.DependencyInjection" version="2.2.0" targetFramework="net47" />

Does anyone know if this error is related to the difference between using app.config and packages.config, or am I on a wild goose chase? And if so, what else can be causing this error and how do I force it to use the 2.2.0 version of the package, like the other assemblies?

c#
.net
entity-framework
asked on Stack Overflow Dec 17, 2019 by Noceo

1 Answer

0

You'll need to change that app.config block to:

<dependentAssembly>
  <assemblyIdentity name="Microsoft.Extensions.DependencyInjection.Abstractions" publicKeyToken="adb9793829ddae60" culture="neutral"/>
  <bindingRedirect oldVersion="0.0.0.0-2.2.0.0" newVersion="2.2.0.0"/>
</dependentAssembly> 

Although I would recommend deleting this block, removing the package and re-adding it.

Microsoft.Extensions.DependencyInjection.Abstractions 3.1.0 targets netstandard2.0, so you could possibly be able to use that, in which case you can keep your app.config file as it is and upgrade the Microsoft.Extensions.DependencyInjection.Abstractions explicitly in your packages.config file.

answered on Stack Overflow Dec 17, 2019 by Stuart • edited Dec 17, 2019 by Stuart

User contributions licensed under CC BY-SA 3.0