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

Athari
  • 33,702
  • 16
  • 105
  • 146
okeziestanley
  • 329
  • 1
  • 4
  • 9
  • 1
    Please provide a [mcve]. 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. – Jon Skeet Aug 08 '17 at 08: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. – Ved Prakash Tiwari Aug 08 '17 at 09: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 – okeziestanley Aug 27 '17 at 18:03
  • Possible duplicate of [Could not load file or assembly System.Net.Http version 4.1.1.0](https://stackoverflow.com/questions/42720421/could-not-load-file-or-assembly-system-net-http-version-4-1-1-0) – VIGNESH ARUNACHALAM Aug 30 '17 at 07: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. – CBHacking Sep 11 '17 at 22:12
  • @CBHacking: That's assuming it's the same situation as the OP though. It's important for the OP to provide the [mcve] IMO. It's also part of the diagnostic work that the OP should be doing to try to solve the problem for themselves before asking. – Jon Skeet Sep 12 '17 at 05:23

4 Answers4

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>
Rado
  • 131
  • 1
  • 4
1

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

Kzryzstof
  • 7,688
  • 10
  • 61
  • 108
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"/>
Ray
  • 187,153
  • 97
  • 222
  • 204
-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>
NightOwl888
  • 55,572
  • 24
  • 139
  • 212
Himal Patel
  • 387
  • 4
  • 19