9

I am building a .Net standard library, which builds fine but on testing, I get this error

HResult=-2147024894 Message=Could not load file or assembly 'System.Net.Http, Version=4.1.1.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified. Source=Library Trial

I have installed System.Net.Http Nuget Package still no success. It's a fresh project so what must I be doing wrong

6
  • 1
    Please provide a minimal reproducible example. We don't know what your project looks like, what the project type is, or how you're testing it. Versioning can be very tricky - the details all matter. Commented Aug 8, 2017 at 8:47
  • Some where in your project is trying to reference the version 4.1.1.1 which is different from the one which is loaded through Nuget. Try searching in packages.config file. and change the version name to the one which you are referencing through Nuget. Commented Aug 8, 2017 at 9:09
  • Thanks, I just gave up and used the new .Net standard 2.0 on VS 2017. And it just works. Thanks Jon, I was using Net standard 1.6 on VS 2015, didn't do anything special, just create a fresh project and reference system.net.http namespace. Thanks Commented Aug 27, 2017 at 18:03
  • Possible duplicate of Could not load file or assembly System.Net.Http version 4.1.1.0 Commented Aug 30, 2017 at 7:09
  • @JonSkeet: The MCVE is trivial to make. Using VS2017 (15.3.3), create a new C# .NET Standard library, with the .NET Framework version at the top set to 4.6.1 (will default to .NETStandard v1.4). Add a static function to it that calls new System.Net.Http.HttpClient();. Create a second C# project in the same solution, this one a desktop console app. Reference the .NETStandard library. In the console app's Main function, call the library's static function. Run as Debug, changing nothing. Behold an exception. It took me longer to write this than it did to repro the issue. Commented Sep 11, 2017 at 22:12

4 Answers 4

13

As Ved Tiwari said above, remove the reference to "4.1.1.1" in your app.config (or solution/project).

For example, I removed the below and it started working again:

<dependentAssembly> <assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-4.1.1.2" newVersion="4.1.1.2" /> </dependentAssembly> 
Sign up to request clarification or add additional context in comments.

Comments

1

To fix that same error within my solution, not only did I remove the bindingRedirect for System.Net.Http from Web.config (see @Rado's answer) but also needed to remove Version, Culture, etc. and HintPath from it's reference in the project file (*.csproj).

Essentially, changed in *.csproj from

<Reference Include="System.Net.Http, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> <HintPath>..\packages\System.Net.Http.4.1.0\lib\net46\System.Net.Http.dll</HintPath> </Reference> 

to

<Reference Include="System.Net.Http"/> 

Comments

1

If you installed the System.Diagnostics.DiagnosticSource dependency, remove it and update System.Net.Http to version 4.1.1.1

3 Comments

No, I don't have that dependency
Remove reference to assembly and then add new reference via Nuget! The actual System.Net.Http version doesn't matter. After removing reference to assembly.
You may be refer this site link
-1

Add following in your web.config file:

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.