extensions icon indicating copy to clipboard operation
extensions copied to clipboard

Could not load file or assembly Microsoft.Extensions.Configuration.Abstractions, Version=3.1.0.0...

Open hugoqribeiro opened this issue 6 years ago • 36 comments

I have a Visual Studio 2019 extension that references Microsoft.Extensions.Configuration v3.1.1.

This assembly gets loaded by a code generator and then that generator fails with the following error:

Could not load file or assembly Microsoft.Extensions.Configuration.Abstractions, Version=3.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60 or one of its dependencies. The system cannot find the file specified.

Notice that the version is 3.1.0.0, not 3.1.1.0 as I was expecting.

I've download the Microsoft.Extensions.Configuration package from nuget.org just to see if there was something wrong with the version of the package download by our build servers. If I open Microsoft.Extensions.Configuration.dll in ILSpy I see that the reference to Microsoft.Extensions.Configuration.Abstractions.dll is indeed to version 3.1.0.0.

The problem is that the package depends on version 3.1.1, which means that it is version 3.1.1.0 of Microsoft.Extensions.Configuration.Abstractions.dll that gets deployed in my extension, breaking assembly resolution.

Is this a bug in the NuGet package?

How can I work around it in the mean time?

hugoqribeiro avatar Feb 04 '20 16:02 hugoqribeiro

See https://github.com/aspnet/announcements/issues/401 - You should be able to workaround this by adding a <PackageReference for the dependency package. This should be fixed in our next servicing update.

Pilchie avatar Feb 04 '20 17:02 Pilchie

Can you try that and let me know if that works around the issues?

Pilchie avatar Feb 04 '20 17:02 Pilchie

It does not. This is a csproj with packages.config (.NET 4.7) (a VSIX for Visual Studio). I've tried referencing the 3.1.0 package in there but the build fails with "Detected package downgrade error".

This reference is really transient:

Modeling.ServiceDesigner.CodeGeneration (NET) references... Primavera.Hydrogen.DesignTime.Specs (NETStandard) that references... Primavera.Hydrogen.Core (NETStandard) that references... Microsoft.Extensions.Logging that references... Microsoft.Extensions.Configuration.Binder that references... Microsoft.Extensions.Configuration that references... Microsoft.Extensions.Configuration.Abstractions

More

Modeling.ServiceDesigner.CodeGeneration also references Primavera.Hydrogen.Core. Other projects in the SLN reference Primavera.Hydrogen.Core.

This results in that the final bin directory that gets packaged in the VSIX file contains version 3.1.1.0 nevertheless.

hugoqribeiro avatar Feb 04 '20 18:02 hugoqribeiro

Ah. @dougbu - here's an example of what we were talking about where packages that support .NET Framework need to have different version requirements than ones entirely on Core.

@hugoqribeiro I think you should be able to work around this by adding an app.config file with a <bindingRedirect entry for that assembly.

Pilchie avatar Feb 04 '20 23:02 Pilchie

Moving out of 3.1.2, since it's unlikely we'll be able to address this in that release.

Pilchie avatar Feb 04 '20 23:02 Pilchie

Why? Isn’t just a question of fixing the reference of Microsoft.Extensions.Configuration to Microsoft.Extensions.Configuration.Abstractions?

hugoqribeiro avatar Feb 05 '20 10:02 hugoqribeiro

We're already locking down to validate what we hope is our final build for 3.1.2.

Pilchie avatar Feb 05 '20 16:02 Pilchie

Please note that Microsoft.Extensions.DependencyInjection is also affected: Microsoft.Extensions.DependencyInjection v3.1.1 has a runtime dependency on Microsoft.Extensions.DependencyInjection.Abstractions v3.1.0

jbaehr avatar Feb 11 '20 14:02 jbaehr

same error here. our codegenerators are failing and we are blocked... Please fix

codehunter13 avatar Mar 23 '20 10:03 codehunter13

@codehunter13 The recommendation here is that you add a binding redirect to the version that is deployed. We can't update the dependency to point to patch versions, or that breaks people that get the assembly via the .NET Core Shared Framework.

AFAIK, the only way for us to fix this would be completely restructure these packages to have different dependencies entirely for .NET Framework, .NET Standard, and .NET Core. That's unlikely to be something we tack for a servicing release, because the risk is too large.

Adding @ericstj in case he has any other ideas.

Pilchie avatar Mar 26 '20 21:03 Pilchie

@Pilchie Your suggested workaround will not work in our case - our .NET 'app' is an add-in to a third-party application and we cannot edit that application's binding redirects. Why does Microsoft.Extensions.DependencyInjection v3.1.3 have a runtime dependency on Microsoft.Extensions.DependencyInjection.Abstractions v3.1.0? When will this be resolved? Could you fix this for us by providing a publisher policy assembly?

("Dll Hell" is here to stay)

jason-daly avatar Apr 15 '20 00:04 jason-daly

😞

davidfowl avatar Apr 15 '20 01:04 davidfowl

Ditto for this being a large issue. Started using the DI framework in common code, but I also have to support existing VB6 applications, and creating a .config for each one is a big issue based on release processes.

EDIT A workaround that works for my situation is rolling back to DependencyInjection version 3.1.0

TimPurdum avatar Apr 15 '20 14:04 TimPurdum

@codehunter13 The recommendation here is that you add a binding redirect to the version that is deployed. We can't update the dependency to point to patch versions, or that breaks people that get the assembly via the .NET Core Shared Framework.

How do you add a binding redirect to a visual studio extension?

Currently i rolled back to version 3.1.0. but now i got the error: Could not load file or assembly 'System.Text.Json, Version=4.0.1.0 Calling assembly : Microsoft.Extensions.Configuration.Json, Version=3.1.0.0 Assembly Name is: System.Text.Json, Version=4.0.1.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51 WRN: Comparing the assembly name resulted in the mismatch: Revision Number

DLL Hell is back :(

codehunter13 avatar Apr 17 '20 09:04 codehunter13

VS allows you to add binding redirects via ProvideBindingRedirectionAttribute

Pilchie avatar Apr 17 '20 15:04 Pilchie

@Pilchie That's good to know, thanks!

Do you have a similar trick at hand for MSBuild tasks? I have this issue with GitVersionTask

jbaehr avatar Apr 17 '20 16:04 jbaehr

I don't think MSBuild has anything yet, although they were looking at it. Paging @rainersigwald for that. In the meantime, I think the guidance has been to use a ToolTask so that you have your own exe and can have your own config.

Pilchie avatar Apr 17 '20 20:04 Pilchie

@jason-daly said:

Why does Microsoft.Extensions.DependencyInjection v3.1.3 have a runtime dependency on Microsoft.Extensions.DependencyInjection.Abstractions v3.1.0?

The reason is because that's the desired before for .NET Core assemblies that might be in the .NET Core shared framework. This allows the newer package to work with any version of the shared framework, and for installing the shared framework to fix things even if the package isn't updated. It's unfortunate (and our team didn't realize) the impact that has on binding redirects when running on .NET Framework. Fixing it is difficult - it basically means multi-targeting a bunch of packages across .NET Framework and .NET Core and .NET Standard, and having different versioning policies in each. Making a change that large and risky for a servicing release isn't something we're very comfortable doing.

Pilchie avatar Apr 17 '20 20:04 Pilchie

Can you please advise as to exactly how we add the "ProvideBindingRedirectionAttribute" to an Azure Function App project / Solution ?

Exact error I am getting is this:

Could not load file or assembly 'Microsoft.Extensions.DependencyInjection.Abstractions, Version=3.1.3.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified. System.Private.CoreLib: Could not load the specified file.

This is quite frustrating to say the least .. Please help.

(targeting - asp.net core 2.2)

phantom2017-Nov avatar Apr 17 '20 22:04 phantom2017-Nov

/cc @joperezr

ericstj avatar Apr 17 '20 22:04 ericstj