Runtime: Cannot load System.Net.Http, Version=4.0.0.0

Created on 6 Dec 2017  路  14Comments  路  Source: dotnet/runtime

I'm using VS 2017. I have a WinForms application that targets .NET Framework 4.6.1 and I am publishing as a ClickOnce app. It uses my own Nuget package that targets .NET Standard 1.4. The Nuget package references System.Net.Http. When I install the application on a client computer. System.Net.Http.dll is not installed, even though it is referenced in the WinForms application. App.config references 4.1.1.1. I have tried copying multiple versions of System.Net.Http to the installed directory, but I get the following error:

System.IO.FileLoadException: Could not load file or assembly 'System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
File name: 'System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'

=== Pre-bind state information ===
LOG: DisplayName = System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
 (Fully-specified)
LOG: Appbase = file:///C:/Users/.../AppData/Local/Apps/2.0/P14YD5BC.CHQ/B0M3BHKE.N0L/reso..tion_e8792805a00774ea_0001.0000_1ce3e8cb7fcdab99/
LOG: Initial PrivatePath = NULL
Calling assembly : IdentityModel.OidcClient, Version=2.2.0.0, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Users\...\AppData\Local\Apps\2.0\P14YD5BC.CHQ\B0M3BHKE.N0L\reso..tion_e8792805a00774ea_0001.0000_1ce3e8cb7fcdab99\Resolve.ROI.QC.ClientWF.exe.config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Redirect found in application configuration file: 4.0.0.0 redirected to 4.1.1.1.
LOG: Post-policy reference: System.Net.Http, Version=4.1.1.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
LOG: Attempting download of new URL file:///C:/Users/.../AppData/Local/Apps/2.0/P14YD5BC.CHQ/B0M3BHKE.N0L/reso..tion_e8792805a00774ea_0001.0000_1ce3e8cb7fcdab99/System.Net.Http.DLL.
WRN: Comparing the assembly name resulted in the mismatch: Minor Version
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.

[EDIT] Mark log as code by @karelz

area-System.Net.Http question

Most helpful comment

The log says, there was post-binding policy to 4.1.1.1. Get rid of it by adding bindingRedirect of System.Net.Http 4.1.1.1 to 4.0.0.0 in your app.exe.config: https://github.com/dotnet/corefx/issues/25588#issuecomment-348044544

All 14 comments

The log says, there was post-binding policy to 4.1.1.1. Get rid of it by adding bindingRedirect of System.Net.Http 4.1.1.1 to 4.0.0.0 in your app.exe.config: https://github.com/dotnet/corefx/issues/25588#issuecomment-348044544

I changed:


      <dependentAssembly>
        <assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
        <bindingRedirect oldVersion="0.0.0.0-4.1.1.1" newVersion="4.1.1.1"/>
      </dependentAssembly>

to:

      <dependentAssembly>
        <assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
        <bindingRedirect oldVersion="0.0.0.0-4.1.1.1" newVersion="4.0.0.0"/>
      </dependentAssembly>

But I still get the redirect to 4.1.1.1 error. The System.Net.Http.dll that I copied has version 4.6.23123.0. Also, the install still does not include System.Net.Http.dll. Is there a way for ensure the dll is installed with the ClickOnce setup?

Thanks

But I still get the redirect to 4.1.1.1 error. The System.Net.Http.dll that I copied has version 4.6.23123.0. Also, the install still does not include System.Net.Http.dll. Is there a way for ensure the dll is installed with the ClickOnce setup?

Is it possible for you to post a small Visual Studio solution (*.ZIP file) that shows this problem? There are added complexities of this scenario being a WinForms application targeting 4.6.x and then being bundled with a ClickOnce setup. So, in order to troubleshoot this, we need to see a complete solution so that we can attempt to repro the problem you are seeing.

@davidsh I can try to create a project. However, if there is another way to accomplish this, I am open to it. Even if I need a different way of deploying it than ClickOnce. I am using WinForms, because of a 3rd party, Nuget package for PDFs that only support WinForms. I am targeting 4.6.1, because my own Nuget targets Net Standard 1.4.

A bit more information, the WinForms app references System.Net.Http. Under properties, the Runtime Versions is 4.0.30319. The Versions is 4.1.1.1. However, I changed Specific Version to false.

@davidsh I created two, test projects that illustrate what I am trying to do.

TestNetStandard14.zip is a .Net Standard 1.4 class library that implements an HttpClient. I publish it as a Nuget package.

TestWF461.zip is a .Net Framework 4.6.1 WinForms application that uses the class library, installed as a Nuget package. I am installing it through ClickOnce.

In my own application, I can install the application. However, it does not include System.Net.Http and a few other libraries. When I build the project, those libraries are included in the Bin directory. However, they are not listed in the Publish - Application Files. Also, when I copy the libraries to the directory, I get the above error regarding versioning.

In the test project, I get errors about required libraries missing, when I try to install, such as System.Drawing.Primitives. Prerequisite (Auto) does not include the required libraries.

TestNetStandard14.zip
TestWF461.zip

@karelz This issue is another example of the packaging/binding-redirects etc. issue when there are projects that target NetStandard and .Net Framework. Perhaps we can resolve this issue against those dupes and provide the link to the "Known Issues" document?

We think this issue is resolved now. Please use the latest Visual Studio 2017 Update 15.7 and .NET Core 2.1 SDK.

Please try out those updates and let us know. If there are still problems, we can re-open the issue. Thx.

I'm using 15.8.9 and still experiencing this issue. I have a WPF app that references both .NET Standard libraries and .NET Framework libraries. It's targeting 4.7.2, and I've already tried the workaround of changing the redirect to newVersion="4.0.0.0" (which works for my 2 web apps in the same solution, although I have to go through and do them every time I do something with Nuget). However in WPF it still doesn't work - I actually get two exceptions where one says it can't find the 4.0.0.0 version and one says it can't find 4.2.0.0. Is there a permanent fix for this issue coming? Having to manually go through and change redirects isn't a great solution, and I'm not even sure what to try next for WPF.

@joperezr - Can you help with this?

Update: it appears unchecking the "auto-generate package redirects" option for the project fixes it (presumably along with the custom app.config redirects to 4.0.0.0). I'd still love to know if a real fix is in the pipeline.

We would need more info in order to investigate this. @kEph13 do you have a simple repro for the WPF issue? How did you add the package references? If your project has packages.config, have you tried deleting the binding redirects in the app.config and then migrating your project to PackageReference?

cc @wtgodbe

It doesn't appear that you can migrate full ASP.NET projects to PackageReference (at least, the docs say it's not supported, and there's no right-click option). I'll try to get a repro together.

Also, even when "Auto-Generate Package Redirects" is un-checked, nuget updates the redirects on every action (even ones that don't affect the System.* packages that are borked). That seems like something that could get looked at as a first step? I get the impression there are a lot of people changing the redirect version to 4.0.0.0 as a workaround.

Yeah there probably isn't a GUI way of migrating your project, but you should be able to do it manually by editing your .csproj file. Let me know when you have that simple repro so that I can take a look.

I had a MVC 5 + Web API 2 project with this error in Visual Studio 2017 15.9.3 targeting .NET Framework 4.6.1. It was referencing a class library with System.Net.Http 4.0.0 as a NuGet dependency. After updating it to 4.3.0 this error appeared.

I found that the MVC project did not reference System.Net.Http from NuGet. After adding it as a NuGet package I got a different error when adding Owin.SecurityOptions: "TypeLoadException: Inheritance security rules violated by type: 'System.Net.Http.WebRequestHandler'". This is a known issue that is fixed by updating to 4.3.1.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jzabroski picture jzabroski  路  3Comments

EgorBo picture EgorBo  路  3Comments

aggieben picture aggieben  路  3Comments

sahithreddyk picture sahithreddyk  路  3Comments

matty-hall picture matty-hall  路  3Comments