runtime: Azure Function fails to load System.Configuration.ConfigurationManager

Description

I have an Azure Function which imports the NuGet Package System.Configuration.ConfigurationManager v5.0.0 The Azure Function is a .NET Core 3.1 app and targets Azure Functions v3.

When I start the function, it crashes with a FileNotFoundException:

 System.IO.FileNotFoundException: Could not load file or assembly 'System.Configuration.ConfigurationManager, Version=5.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.
File name: 'System.Configuration.ConfigurationManager, Version=5.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'

When I look at my filesystem, I notice that the assembly System.Configuration.ConfigurationManager.dll is not present in the netcoreapp3.1\bin folder, whereas all my other assemblies that I require in my function are there. However, the assembly is present in the netcoreapp3.1 folder.

When I downgrade to a previous version (4.7.0), I don’t have this issue. (I can also see that the assembly System.Configuration.ConfigurationManager.dll is now present in the netcoreapp3.1\bin folder.

Configuration

.NET Core 3.1 Azure Functions v3 Targetting a Linux App Service

Regression?

As mentionned in the description, it works with version 4.7.0 of System.Configuration.ConfigurationManager in a .NET Core 3.1 app.

Other information

Probably related to https://github.com/dotnet/runtime/issues/627

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 1
  • Comments: 24 (7 by maintainers)

Most upvoted comments

Can you share a minimal repro project so that I can take a peek? This may just be a problem with VS publish to Azure.

You can already reproduce it running locally. Just create an Azure Function, reference the package and run locally.

I’ve created a sample repo here. This sample consists of a timer-triggered Azure Function that throws a ConfigurationErrorsException on each invocation. You’ll see that, instead of the ConfigurationErrorsException being thrown, a FileNotFoundException is thrown.

Following up on a conversation with @joperezr and sharing it here.

Yes, this makes sense in Azure Functions due to the current unification rules in V3. For V4 (shipping with .NET 6 RTM), the unification rules have been revised and the number of assemblies there has been significantly reduced. System.Configuration.ConfigurationManager is no longer unified there and application should be able to bring any version of that dependency they wish.

It’s also worth mentioning that another option is the out-of-proc/isolated model , which gives you full control over the process and dependencies.

About the error message, I’ll bring this up again in our next triage and it is something we can improve to make scenarios like this clearer.

I’m also experiencing this issue, on both .NET 5.0 and 6.0-preview. I found downgrading the System.Confguration.ConfigurationManager from 5.0.0 to 4.7.0 resolves the issue - though of course that’s not ideal.

Same here… I opened another ticket which was classified as a duplicate: https://github.com/dotnet/runtime/issues/60516

I also have the problem with Azure functions V4 with Net6 and also provided a sampe project to reproduce the issue.

I’m investigating this now. The root cause seems to be that Azure Functions runtime is using a custom AssemblyLoad Context which is pinning the version of System.Configuration.ConfigurationManager (and other packages). This seems to be causing that anytime you try to use a newer version of this assembly than the one shipping with their runtime, they will fail to load it, which is what we are seeing here. I found an interesting article talking about the roadmap for Azure functions where they call out this specific problem:

… However, sharing the same process does come with some tradeoffs. In earlier versions of Azure Functions, dependencies could conflict (notable conflicting libraries include Newtonsoft.Json). While flexibility of packages was largely addressed in Azure Functions V2 and beyond, there are still restrictions on how much of the process is customizable by the user. Running in the same process also means that the .NET version of user code must match the .NET version of the host. These tradeoffs of sharing a process motivated us to choose an out-of-process model for .NET 5. …

Tagging @fabiocav from the Azure Functions team. Does this ring any bells? If it turns out that this is the root cause of the issue that we are seeing here, is there any chance that we can have Azure Functions runtime to throw a more detailed exception that can help guide users understand the root cause of the issue?