'Could not load file or assembly 'Microsoft.Extensions.Configuration.Abstractions, Version=5.0.0.0 in Azure Functions

I have an API and a separate Azure Functions app. I upgraded my API app to .NET 5 and it's working fine. In the API app's solution, I have class library projects that I also reference in my Azure Functions app. These class libraries are netstandard2.1 projects.

Ever since this update -- during which I also updated all my NuGet packages to latest versions -- my Azure Functions app stopped working. I'm getting the following error:

Could not load file or assembly 'Microsoft.Extensions.Configuration.Abstractions, Version=5.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified. Value cannot be null. (Parameter 'provider')

I noticed that there were breaking changes involving the Microsoft.Extensions.* packages and their recommendation is to install the package that is causing the issue directly. So I added Microsoft.Extensions.Configuration.Abstractions to my Azure Functions manually -- before it was being installed as a dependency of Microsoft.Extensions.Configuration package. Here's the information about this: https://github.com/dotnet/aspnetcore/issues/21033

The issue still persists. I even tried downgrading Microsoft.Extensions.Configuration in both the API and Functions app, but I'm still getting the same error.

Any idea how to resolve this issue?



Solution 1:[1]

Sam's comment should be accepted as correct answer. I try it out to downgrade Microsoft.Extensions* (in my case Microsoft.Extensions.Logging.Console) from 5.0.0 to 3.1.0 and the error just gone. Bravo!

Solution 2:[2]

As a reference, this GitHub link explains exactly why that happens.

And as of now, you either track down the exact versions been referenced or downgrade everything to the latest v3 build.

In a nutshell, Azure Functions SDK already has some dependencies loaded in memory, so your libraries cannot use newer versions of the same libraries.

Solution 3:[3]

If you are upgrading from .NET Core 3.1 to .NET 6 and you get this error, you need to change the Azure functions version to v4 and it fixes this error.

Solution 4:[4]

As @binaryDi mentioned in their answer, you need to downgrade packages that reference version 5 of Microsoft.Extensions.Configuration.Abstractions.

This can be a bit of a pain, as it doesn't tell you which packages are actually referencing Microsoft.Extensions.Configuration.Abstractions package/namespace.

For me, I had to update Microsoft.Extensions.Caching.Memory and Microsoft.EntityFrameworkCore.SqlServer to a version before 5. Anything that is referencing dotnet 5 should be downgraded for the Azure Function to run.

Solution 5:[5]

Adding this answer in case it helps anyone upgrading from .NET 3.1 to .NET 6.0.

First, as per @Jeff's answer, make sure you reference v4 in the Azure Functions project .csproj file:

<AzureFunctionsVersion>v4</AzureFunctionsVersion>

In my case, however, this was already set.

The Azure Function was running fine locally however in Azure DevOps pipeline I was getting the error described by the OP.

I noticed that when debugging the Azure Function locally, the console was outputting:

Azure Functions Core Tools
Core Tools Version:       4.0.3928 Commit hash: 7d1d4a32700695bbf290a871c7492fde84bb767e  (64-bit)
Function Runtime Version: 4.0.1.16815

In my case I am actually running the Azure Function in an Azure DevOps pipeline for e2e test purposes. To achieve this, I first install the Azure Function Core Tools on the build agent using this npm command:

npm install azure-functions-core-tools -g

However this installs [email protected] (version 3.x - NOT the latest version 4.x).

I then installed Azure Function Core Tools (v4), e.g. by installing with this npm command.

npm i -g azure-functions-core-tools@4 --unsafe-perm true

And this (for me) resolved the error.

Whether or not this is your exact scenario, make sure you are using Azure Function Core Tools v4.x if using Azure Function Runtime v4 and .NET 6.

Solution 6:[6]

I stumbled upon this question while looking for an answer to my problem with upgrading to .NET 6.0. There was no going back, because I've bought a Macbook with an M1 processor and Arm support only works decently in .NET 6.0

Putting <AzureFunctionsVersion>v4</AzureFunctionsVersion> wasn't enough, because that doesn't increase the runtime version on Azure.

My function was already running on version 3.0 and strangely I couldn't select v4.0 in the portal. I had to change the version through the Azure CLI.

More information on how to do that can be found here: https://docs.microsoft.com/en-us/azure/azure-functions/set-runtime-version?tabs=azurecli

Solution 7:[7]

I also ran into this error when upgrading a c# func project from version 3 to 4.

I had already set <AzureFunctionsVersion>v4</AzureFunctionsVersion> but that didn't solve it.

The answer by @neeohw pointed me to the solution that fixed it for me, but I had to dig a bit further, and this is what fixed it for me:

Do the Azure cli commands as specified here: https://docs.microsoft.com/en-us/azure/azure-functions/functions-versions?tabs=in-process%2Cv4&pivots=programming-language-csharp#azure

I suggest you read that section for a background understanding, but the commands that ran was these:

az functionapp config appsettings set --settings FUNCTIONS_EXTENSION_VERSION=~4 -n <APP_NAME> -g <RESOURCE_GROUP_NAME>

# For Windows function apps only, also enable .NET 6.0 that is needed by the runtime az functionapp config set --net-framework-version v6.0 -n <APP_NAME> -g <RESOURCE_GROUP_NAME>

Solution 8:[8]

I also ran into this error when upgrading a c# function project from NETCORE 3.1 to .NET 6.

I set the following in the project (.csproj).

<AzureFunctionsVersion>v4</AzureFunctionsVersion>

AND also changed the Application setting value in the Function App - Configuration Section (Azure Portal)

"FUNCTIONS_EXTENSION_VERSION" from "~3" to "~4"

and that fixed it for me.

Solution 9:[9]

In my case, the reason was Microsoft.EntityFrameworkCore version 5.0.2.

I donwgraded it to version 3.1.18.

(Other related packages, such as Microsoft.EntityFrameworkCore.Design, Microsoft.EntityFrameworkCore.SqlServer, and Microsoft.EntityFrameworkCore.Tools should also be downgraded to 3.1.18.

Solution 10:[10]

I had this error when I used the latest of version Npgsql.EntityFrameworkCore.PostgreSQL which is 5.0.7 as this time of writing. I had to downgrade to 3.1.11 for the current version has a dependency to the 5.0.0.0 version of Microsoft.Extensions.Configuration.Abstractions.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 binaryDi
Solution 2 Daniel
Solution 3 janw
Solution 4 Newteq Developer
Solution 5 Dan Cook
Solution 6 neeohw
Solution 7 Jonas
Solution 8 Juan P. Garces
Solution 9 Jeremiah Flaga
Solution 10 Raffy