Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could not load file or assembly 'System.Net.Http

Tags:

c#

.net

asp.net

In my diagnostic view of my build output shows this conflict

There was a conflict between "System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" and "System.Net.Http, Version=4.1.1.2, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a". (TaskId:20) "System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" was chosen because it was primary and "System.Net.Http, Version=4.1.1.2, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" was not. (TaskId:20) References which depend on "System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" [C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.6.1\System.Net.Http.dll]. (TaskId:20)

I got here by adding the RestSharp nuget package. I was not having an issue until I installed this and I think one of the pieces that came with it may have caused this issue. I tried to uninstall it but that did not work.

like image 691
Dan Avatar asked Nov 07 '17 03:11

Dan


People also ask

Can not load file or assembly?

In summary if you get the "Could not load file or assembly error", this means that either your projects or their references were built with a reference to a specific version of an assembly which is missing from your bin directory or GAC.

What is System Net HTTP?

Provides a programming interface for modern HTTP applications, including HTTP client components that allow applications to consume web services over HTTP and HTTP components that can be used by both clients and servers for parsing HTTP headers. Commonly Used Types: System.


2 Answers

Installing Nuget Package: System.Net.Http version 4.3.3 installs the correct Version=4.1.1.2

this will result in the following reference in your project file:

<Reference Include="System.Net.Http, Version=4.1.1.2, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">       <HintPath>..\..\..\..\packages\System.Net.Http.4.3.3\lib\net46\System.Net.Http.dll</HintPath> </Reference> 
like image 104
Gerrie Pretorius Avatar answered Oct 05 '22 23:10

Gerrie Pretorius


If you using vs2017, some project will force u reference to system.net.http (4.2.0.0) When you install from nuget (version 4.3.3) and your system.net.http will be 4.1.1.2

-> it will be conflict

So in your web.config or app.config, you can change to 4.1.1.2 or 4.2.0.0 depend on which version was copy to bin folder when runtime

<dependentAssembly>         <assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />         <bindingRedirect oldVersion="0.0.0.0-4.2.0.0" newVersion="4.1.1.2" />       </dependentAssembly> 
like image 26
Grey Wolf Avatar answered Oct 06 '22 00:10

Grey Wolf