Could not load file or assembly Microsoft.Extensions.DependencyInjection.Abstractions, Version=5.0.0.0 with EF core 5.0-rc1
Case
We are creating azure function v3 with .netcore 3.1. Using EF core 5.0-rc1 and Depdency Injection
1) DependecyInjection
[assembly: FunctionsStartup(typeof(xxxxx.Startup))]
namespace xxxxx
{
public class Startup : FunctionsStartup
{
public override void Configure(IFunctionsHostBuilder builder)
{
var services = builder.Services;
var configBuilder = new ConfigurationBuilder()
.SetBasePath(Environment.CurrentDirectory)
.AddJsonFile("local.settings.json", true, reloadOnChange: true)
.AddEnvironmentVariables() ;
ConfigureServices(services);
ConfigureAppSettings(services, configBuilder.Build());
ConfigureLogging(services, configBuilder.Build());
}
}
}
2) EF core 5.0 rc-1
https://devblogs.microsoft.com/dotnet/announcing-entity-framework-core-efcore-5-0-rc1/
Error
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.

Packages
Following are the packages referenced

<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<AzureFunctionsVersion>v3</AzureFunctionsVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.1.0" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.ServiceBus" Version="4.1.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="5.0.0-rc.1.20451.14" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.7" />
<PackageReference Include="Serilog.Extensions.Logging" Version="3.0.1" />
<PackageReference Include="Serilog.Sinks.Console" Version="3.1.1" />
</ItemGroup>
<ItemGroup>
<None Update="host.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="local.settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
</ItemGroup>
</Project>
Troubleshooting
commenting the following line in startup.cs (Dependency injection) solves the problem
[assembly: FunctionsStartup(typeof(xxxxx.Startup))]
I got the root cause of the problem. Microsoft.Azure.Functions.Extensions supports upto .NET Standard 2.0 whereas ef core will not run on .ent standard 2.0


Hi,
This is preventing us currently from using EF Core 5's improved Cosmos querying capability in our dotnet function app, which kind of kills using it for our use case as we can't afford the memory of querying client-side. When will this be fixed?
I had the same issue. I just created a new azure function (timer triggered) project to check if it was something on my main project, and I got the same error on a basic function template. I only updated Microsoft.Extensions.DependencyInjection from 3.1.0 to 5.0.0 and starting the project I got the error message: A host error has occurred during startup operation '7b3dd83a-88a1-4025-bedd-ce743a42abe0'. [2020-11-13T02:10:03.279Z] FunctTeste: Could not load file or assembly 'Microsoft.Extensions.DependencyInjection.Abstractions, Version=5.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. O sistema não pode encontrar o arquivo especificado. Value cannot be null. (Parameter 'provider').
That's my csproj content:
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<AzureFunctionsVersion>v3</AzureFunctionsVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.1.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="5.0.0" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.11" />
</ItemGroup>
thx
I had the same issue. Downgrading Microsoft.Extensions.DependencyInjection from 5.0.0 to 3.1.10 seems to have resolved my issues.
Same issue Could not load file or assembly 'Microsoft.Extensions.Logging.Abstractions, Version=5.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.
I had to downgrade Microsoft.Extensions.Http from 5.0.0 to 3.1.10 since it depended on Microsoft.Extensions.DependencyInjection.Abstractions 5.0.0
It seems any version 5.0.0 NuGet package will cause this. I had to downgrade "Microsoft.EntityFrameworkCore.SqlServer" to 3.1.x
Also encountered this with
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="5.0.0" />
Reverting to 3.1.0
Currently utilizing Microsoft.NET.Sdk.Functions v 3.0.11 and Function.Extensions 1.1.0 Targetting Core 3.1 with other libraries as Standard 2.1
.NET 5 is not currently supported in Azure Functions V3. Reverting to 3.* versions appears to be the standard response to this issue.
It is on the Azure Functions roadmap - https://github.com/Azure/azure-functions-host/issues/6674.
Yes, downgrade everything from 5.0.0 to 3.1.10. It will work fine.
As i commented in https://github.com/Azure/azure-functions-host/issues/6893#issuecomment-726386105
- when you run azure functions, it starts before it loads your code.
- only 1 version of a dll can be loaded at once.
Consequence: if you need a library that is a direct or indirect dependency of azure functions you can only use the version that is loaded. This is a case where azure functions is incorrectly reporting its hard dependencies.
eg: if you are using azure functions 3.0.7, then you must use a library binary compatible with dependencyInjection.abstractions 2.1.0 When your code (eg if you have a asp.netcore dependencency) asks for something that is only found in Abstractions >=5.0 the runtime (correctly) responds "sorry, that function isn't there", because all it has is the 2.1.0 dll in memory.

Therefore the many tickets that will be raised that are like this can only be solved by upgrading azure functions to a newer version which has a dependency on the 5.x line of the abstractions.
In this particular case, if azure functions used Microsoft.Extensions.DependencyInjection.Abstractions 5.0, then it would be fine because that library appears to be backwards compatible so the reverse error doesn't occur (no runtime failure if you expect 2.1 and actually get 5.0).
If that is not true for all libraries in common between azure functions and the libraries your code uses, then you will be pinned in terms of your dependencies and azure functions versions.
@rupeshtech FYI your root cause is mistaken i belive...an assembly requiring standard 2.0 means it'll work on 2..0+ this is really caused as @AartBluestoke explained
Agree to @drdamour and @AartBluestoke. I just downgraded all my project references to 3.1.10 and it worked fine. EVen though the class libraries in the project are .NET Standard 2.1.
Thanks @AartBluestoke for the comment.
So I was battling this for hours, I did everything suggested here and still no fix. I randomly decided to clean solution and to my amazement, it now runs as expected...
Good ol' mickysoft.
I had the same issue. Downgrading Microsoft.Extensions.DependencyInjection from 5.0.0 to 3.1.10 seems to have resolved my issues.
Life saver. My hole project targets .NET Core 3.1 and I would expect NuGet to pick only compatible packages, but that wasn't the case. This helped my proceed further.
Life saver. My hole project targets .NET Core 3.1 and I would expect NuGet to pick only compatible packages, but that wasn't the case. This helped my proceed further.
Nuget did, the 5.x stuff is compatible with std 2.1/core 3.1 its functions runtime that is restrictive
Yes, downgrade everything from 5.0.0 to 3.1.10. It will work fine.
Works for me as well.
I cannot downgrade because Microsoft.AspNetCore.Components requires >= 5.0.0
I am unable to migrate my app to .NET 5
I was using the PackageReference Include=" Microsoft.Azure.Functions.Extensions" Version="1.1.0" and it references the Microsoft.Extensions.DependencyInjection Microsoft.Extensions.Options.ConfigurationExtensions and this issue starts to happen when I updated those references in a class library project. which made the Azure function app see the 5.* version. and as stated those are not supported yet in Azure Functions version 3 so had to downgrade those references in all projects in the solution. once I rolled back to the old version 3.1.14 everything worked fine.
Hi I was encountering the same issue while importing a class library with .NET Core 3.1 on the latest v5.0.1 DI SDK. Once I downgraded the DI dependency to v3.1.10 the issue can be mitigated. However I do want the fix deployed on the latest version, since I can see ~v6 is in preview but the issue has not been addressed.