Sam
Sam

Reputation: 30388

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?

Upvotes: 71

Views: 120040

Answers (14)

Robbie
Robbie

Reputation: 337

I had this error when I was upgrading a functions app from .net core 3.1 to .Net 6.0.

I had followed all of the correct upgrade steps here but was still getting the error:

Could not load file or assembly 'Microsoft.Extensions.Configuration.Abstractions, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified. .

The issue was my deployment pipeline was still targeting 3.1, using the Azure Functions deployment task you can select the runtime definition. So, even though I had made all of the changes required on the Function App itself and within the solution, my pipeline was causing the issue.

Upvotes: 1

Andres Talavera
Andres Talavera

Reputation: 2200

I was this error on my Mac (arm) when I tried to ran my functions (.NET6) locally.

In my case, I tried your solution and the functions still would not start and I still had this log in the console: Could not load file or assembly 'Microsoft.Extensions.Configuration.Abstractions, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified..

I realized that I had installed 2 instances of azure tools (v3 with HomeBrew and v4 with npm). When I run func start to start my functions, I observed that v3 was used. So I uninstalled the v3 tools with HomeBrew to use v4 with npm).

Upvotes: 0

Tarun Bhatt
Tarun Bhatt

Reputation: 817

I had the same issue and the configuration for Azure FunctionsVersion was already present.

<AzureFunctionsVersion>v4</AzureFunctionsVersion>

I was able to resolve the issue by downgrading the version of Microsoft.Extensions.Http from 7 to 6

<PackageReference Include="Microsoft.Extensions.Http" Version="6.0.0" />

Upvotes: 4

Prem
Prem

Reputation: 432

The issue was occurring to me, when I was trying to host an upgraded function in Azure functions. The previous version was targeted to netcoreapp3.1, which I upgraded to target net6.0 and, set v4 as Azure Function version.

The error was "Could not load file or assembly 'Microsoft.Extensions.Configuration', Version=6.0.0.0 in Azure Functions"

After spending couple of hours, I figured that its the startup class that was causing the issue because it was the only place Configuration was used.

Changing the Startup to inherit from FunctionsStartup rather than WebJobsStartup, fixed the issue. And with slight adjustments, it worked.

[assembly: FunctionsStartup(typeof(Startup))]

...

public class Startup : FunctionsStartup { ... 

public override void Configure(IFunctionsHostBuilder builder)
    {

        var configuration = new ConfigurationBuilder()
            .AddEnvironmentVariables()
            .Build();

        builder.Services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();

        builder.Services.AddHttpClient();

        ...
     }

That's it!

Upvotes: 1

Juan P. Garces
Juan P. Garces

Reputation: 117

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.

Upvotes: 5

Jonas
Jonas

Reputation: 665

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://learn.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>

Upvotes: 2

neeohw
neeohw

Reputation: 595

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://learn.microsoft.com/en-us/azure/azure-functions/set-runtime-version?tabs=azurecli

Upvotes: 3

Dan Cook
Dan Cook

Reputation: 2072

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.

Upvotes: 11

Jeff Mikan
Jeff Mikan

Reputation: 499

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.

Upvotes: 39

Raffy
Raffy

Reputation: 605

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.

Upvotes: -1

jflaga
jflaga

Reputation: 4779

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.

Upvotes: -1

Newteq Developer
Newteq Developer

Reputation: 2647

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.

Upvotes: 9

Daniel
Daniel

Reputation: 1484

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.

Upvotes: 29

binaryDi
binaryDi

Reputation: 2133

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!

Upvotes: 43

Related Questions