65

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?

6
  • 5
    For me, downgrading the Microsoft.Extensions.* NuGet packages to version 3.1.10 stopped this issue, so I think you're onto something with the Microsoft.Extensions refactoring being the problem. I had to do a clean build, and I had to exit VS and restart it.
    – Chris Rae
    Commented Nov 13, 2020 at 6:32
  • Ran across this same issue. Here is the reference in the official documentation learn.microsoft.com/en-us/dotnet/core/compatibility/….
    – Gary Chan
    Commented Nov 13, 2020 at 16:13
  • 2
    The fix on that page (to manually reference Microsoft.Extensions.Configuration.Abstractions) did not work for me. Could be some sort of specific issue with Azure Function deployment?
    – Chris Rae
    Commented Nov 13, 2020 at 16:32
  • 12
    @ChrisRae You're right! Downgrading Microsoft.Extensions.* to 3.1.10 does fix the issue. It didn't work for me before because I had only downgraded Microsoft.Extensions.Configuration but not Microsoft.Extensions.DependencyInjection. Clearly, there are shared libraries so ALL Microsoft.Extensions.* have to be downgraded. Thank you!
    – Sam
    Commented Nov 13, 2020 at 18:35
  • 3
    @GaryChan As @ChrisRae mentioned, installing Microsoft.Extensions.Configuration.Abstractions does not for me either! The only solution seems to be go back to version 3.1.10 on ALL Microsoft.Extensions.* packages.
    – Sam
    Commented Nov 13, 2020 at 18:37

14 Answers 14

43

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!

2
  • 1
    Same thing if you're using Entity Framework. Downgrade it from version 5.0.9 to version 3.1.18. Had the same problem but found the bug inside Microsoft.EntityFrameworkCore* packages. Commented Sep 6, 2021 at 9:31
  • We got the same error for the 7.0.0 version and solved it by downgrading Npgsql.EntityFrameworkCore.PostgreSQL package from 7.0.0 to 6.0.0
    – Tekin
    Commented Nov 16, 2022 at 14:29
39

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.

6
  • THANK YOU! Saved me a bunch of time.
    – mlienau
    Commented Dec 2, 2021 at 14:03
  • 8
    @CaptainPrinny not NuGet package but this value in the .csproj of the Azure Function: <AzureFunctionsVersion>v4</AzureFunctionsVersion>
    – Dan Cook
    Commented Jan 25, 2022 at 5:35
  • 13
    I already have it v4, still it is not working for me. Any other wayout ? <TargetFramework>net6.0</TargetFramework> <AzureFunctionsVersion>v4</AzureFunctionsVersion>
    – ispostback
    Commented Dec 15, 2022 at 9:41
  • 4
    .NET 7, v4, still have the issue Commented Jun 30, 2023 at 1:24
  • 1
    still wasn't working for me either so I had to downgrade "Microsoft.Extensions.Http" from "8.0.0-rc.1.23419.4" to "6.0.0"
    – Biraj Saha
    Commented Sep 26, 2023 at 11:24
29

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.

1
  • Thanks for the link. Precisely described the issue and fix!
    – Ashutosh
    Commented Nov 24, 2021 at 20:42
11

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.

3
  • Oh, this is extremely useful information and we just ran into it, as well, also doing a 3.1 to 6 migration. Our tracking history shows that we actually encountered this on our attempt to update to .NET 5 as well. Commented Jan 31, 2022 at 14:17
  • Though, for clarification, are you singly deploying the one Azure Function on a larger pipeline? We currently have a project with the functions in the same solution as the main application, and I don't know if a generalized build agent install is going to work to cover all the bases here. Commented Jan 31, 2022 at 15:21
  • Just added this to the top of our pipeline for multiple things, seems to be as simple as that. Not sure why it's necessary, but I hope other people end up here. Commented Jan 31, 2022 at 21:03
8

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.

6
  • Cool, but now what about .NET 6 Commented Jan 24, 2022 at 19:20
  • I'm not quite sure. Since .NET 6 is LTS, my best guess is that it should work for .NET 6. But we haven't upgraded our function yet, so I cannot confirm Commented Jan 25, 2022 at 12:06
  • @NewteqDeveloper let me know, when you do so. I already have it v4, still it is not working for me <TargetFramework>net6.0</TargetFramework> <AzureFunctionsVersion>v4</AzureFunctionsVersion>
    – ispostback
    Commented Dec 15, 2022 at 10:24
  • @ispostback That is so strange. .Net 6 is the LTS version; so everything with the functions should work correctly now that you're on 6. Unfortunately, we decommissioned all our functions and went with a different custom built approach for this so I can't verify anymore. If you are still having trouble on .NET 6 specifically, I would definitely advise reaching out to MS themselves, because 6 is LTS, so it should be supported by everything in Azure. 5 was STS so it may not have received the same TLC Commented Dec 19, 2022 at 15:20
  • Downgrading is not a solution, and especially not now that 3.1 is unsupported Commented Jun 30, 2023 at 1:32
5

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.

1
  • This worked for me. Azure Functions Net5 and Entity Framwork 5.0. I was about to downgrade everything to Core 3.1 Commented Jun 24, 2022 at 17:03
4

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" />
2
  • Didn't work for me
    – ispostback
    Commented Dec 15, 2022 at 10:29
  • may be u need to try other solutions on this page in that case Commented Dec 15, 2022 at 22:08
3

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

2

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>

1

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!

2
  • Maybe a little more details
    – ispostback
    Commented Dec 15, 2022 at 10:30
  • @ispostback, I was not able to dig deep on the difference between functionsStartup and WebJobsStartup. I figured the difference when eliminated few classes and left with bare skeleton code :-) .
    – Prem
    Commented Dec 17, 2022 at 5:59
1

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.

0

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).

-1

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.

1
  • 2
    Not being able to use EF5 isn't really a solution. Commented Jan 24, 2022 at 19:18
-1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.