-2

Background: I developed a .NET Standard 2.0 Nuget package (local) for a class library with a dependency on Microsoft.Extensions.Configuration, Version=2.1.1.0. It passed unit tests and ran fine when invoked from a .NET Core 2.0 console app. However, when I added my package to an Azure Function project it caused an exception to be thrown whenever I attempted to run the azure function from the VS2017 debugger.

  • System.Private.CoreLib: Could not load file or assembly 'Microsoft.Extensions.Configuration, Version=2.1.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60

Question: How can I fix the problem?

Liam
  • 27,717
  • 28
  • 128
  • 190
wpqs
  • 657
  • 1
  • 7
  • 18
  • 2.1.1 requires .NET Core 2.1, so if that's not supported by Azure Functions yet, that would explain the issue and why it worked locally (assuming you have the 2.1.3xx SDK installed). – Martin Costello Jul 31 '18 at 13:41
  • Consider editing your post to include a question and posting your findings/solution as the answer. – trix Jul 31 '18 at 13:45
  • The dependencies given for Microsoft.Extensions.Configuration v2.1.1 are .NETStandard, version=v2.0 and Microsoft.Extensions.Configuration.Abstractions (>= 2.1.1). However, you are probably right that the cause relates to lack of Core 2.1 support. If my Azure Function project doesn't support a dependency of a package that I'm adding, isn't that something that the package manager should report? – wpqs Jul 31 '18 at 13:49
  • I've added a wiki answer for now and removed the answer from your question. If you wish to add your own answer let me know and I'll delete the one I added below. – Liam Aug 01 '18 at 08:06
  • Possible duplicate of [How to resolve NuGet dependency hell](https://stackoverflow.com/questions/32739610/how-to-resolve-nuget-dependency-hell) – Liam Aug 01 '18 at 08:06
  • Please read the guidance on [self answering questions](https://stackoverflow.com/help/self-answer). Please note that SO isn't a forum or a blog post it's a question and answer site. Questions are expected to be [on topic](https://stackoverflow.com/help/dont-ask) and answerable. If clarification is required please do this in comments. – Liam Aug 01 '18 at 08:09
  • I don't agree with Liam's comments. Stack Exchange policy encourages people to answer their own questions so it is reasonable to ask a question and then provide the answer in the same post. This saves people from having to scroll down and read through lots of tedious comment ;-) Further, Liam's suggestion that I am writing a blog, creating a forum post, or off-topic are unwarranted. This posting is clearly a Q/A. – wpqs Aug 08 '18 at 03:04
  • @wpqs Site policy encourages answering questions *in the answers*. Adding an answer to the question makes the question stop making sense and breaks the site’s model. Please read about [**How to Ask questions**](http://stackoverflow.com/questions/how-to-ask) and [**How to Answer questions here**](http://stackoverflow.com/help/how-to-answer). – elixenide Aug 09 '18 at 00:35

2 Answers2

1

Copied from OPs question:

Answer: The problem goes away when I downgraded to Microsoft.Extensions.Configuration, Version=2.0.0. in my package, republished it and then reinstalled it in my Azure Function. This seems to be another example of the packages-dependency-crisis. The Nuget package manager should have caught any dependency problems with v2.1.1 when my package was added to the Azure Function project, but it didn't so it only became apparent at runtime. This is sub-optimal.

I provide the above information in the hope that others will not waste a day tracking down the same issue. It also raises the question as to how you decide what version of a package to add. Clearly in the case of Microsoft.Extensions.Configuration adding the latest stable version isn't always the best idea.

Liam
  • 27,717
  • 28
  • 128
  • 190
0

I know this is an older question but ran into the same issue downgrading a project from 2.2 to 2.1. And removed the user of ASPNetCore.All to ASPNetcore.App. This showed me how many packages we really had to depend on, as well as this issue eventually came up. My error came from the Usersecrets retrieval. Since I was missing: Microsoft.Extensions.Configuration.UserSecrets

hope this can help someone like me who was stuck on this. Should have known it would be a missing package.

Stephen09
  • 33
  • 4