9

In my azure function app project, I receive an assembly not found runtime error Microsoft.Extensions.DependencyInjection.Abstractions, Version=5.0.0.0. However, the assembly is included in multiple packages I installed from NuGet.

Visual Studio: 2019 Target Framework: netcoreapp3.1 Azure Functions Version: v3

Installed packages containing Microsoft.Extensions.DependencyInjection.Abstractions (5.0.0):

  • Microsoft.Extensions.Http (5.0.0)
  • Microsoft.Extensions.Logging (5.0.0)
  • Microsoft.Extensions.Logging.EventSource (5.0.0)

Error: A host error has occurred during startup operation... 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.

Ineffective fix attempts: Installed Microsoft.Extensions.DependencyInjection.Abstractions (5.0.0) from NuGet, but error persists.

Following a similar issue, Microsoft.Extensions #2931, and StackOverflow question, I added to the project file the following.

<PropertyGroup> <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> 
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType> </PropertyGroup>

I also followed an article suggestion. After installing Microsoft.Azure.Functions.Extensions, the error persists.

I also followed another suggestion, and I added the following to my project file. However, the error persists.

<runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> 
<assemblyIdentity name="Microsoft.Extensions.DependencyInjection.Abstractions" 
publicKeyToken="adb9793829ddae60" culture="neutral" /> <bindingRedirect oldVersion="5.0.0.0" 
newVersion="5.0.0" /> </dependentAssembly> </assemblyBinding> </runtime>

I attempted the workaround suggested in issue #401 of ASP.NET Core Announcements: reference the package for the assembly which is failing to load explicitly in my application. However, the error remains.

Using ILSpy, I found Microsoft.Azure.Functions.Extensions, which I installed from NuGet, references Microsoft.Extensions.DependencyInjection.Abstractions, Version 2.1.0.0.

SemperCognitaZ5
  • 91
  • 1
  • 1
  • 3

2 Answers2

8

Microsoft.Extensions.DependencyInjection.Abstractions, Version=5.0.0.0 - Looks like you are referring some parent nuget packages meant for .net 5 which depends on this. At the time of this writing, Azure Function does not yet support .net 5 (so quite possible see such issue from a forced v5 nuget reference as Function host works a bit differently than a regular asp.net core app) UPDATE: Now supported. Track this for future update. So, when needed, use only the 3.1.x latest version (not 5 yet) of any relevant nugets like Microsoft.Extensions.* or Microsoft.AspNetCore.*.

N.B. Ideally you should not require any of those packages explicitly in Function though unless you need to do something special.

krishg
  • 5,935
  • 2
  • 12
  • 19
  • To run my Azure Function project locally, I resolved missing assembly Microsoft.Extensions.DependencyInjection.Abstractions, Version=5.0.0.0 runtime error by referencing old versions of all its dependent DLLs and by including multiple old versions of this assembly. However, I received errors from GitHub Workflow CI/CD when attempting deployment to Azure: NU1605: Detected package downgrade To deploy, I resolved by including in project file old versions of pkgs dependent on a common version of original missing assembly. https://github.com/dotnet/extensions/issues/3694#issuecomment-733779020 – SemperCognitaZ5 Nov 25 '20 at 16:16
  • Can you share your nuget reference list from csproj file? – krishg Nov 25 '20 at 16:22
0

The related StackOverflow question, which links to issue Azure/azure-functions-vs-build-sdk #472 and finally to issue Azure/azure-functions-host #6893. GitHub user, @AartBluestoke, summarized: "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."

SemperCognitaZ5
  • 91
  • 1
  • 1
  • 3