1

I wrote simple console application.

static void Main(string[] args)
{
    new HttpClient().PostAsJsonAsync("URL", "Text");
}

And added System.Net.Http and System.Net.Http.Formatting referenes to project.

I get this exception:

An unhandled exception of type 'System.IO.FileLoadException' occurred in System.Net.Http.Formatting.dll

Additional information: Could not load file or assembly 'Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

DonBoitnott
  • 10,011
  • 6
  • 42
  • 63
Aminion
  • 345
  • 1
  • 3
  • 13
  • What IDE? Did you check the libraries' locations and expected locations? – D. Ben Knoble Feb 02 '15 at 21:26
  • 1
    Do you have the Newtonsoft.Json dependency? – Luminous Feb 02 '15 at 21:28
  • Check this [link](http://stackoverflow.com/questions/215026/the-located-assemblys-manifest-definition-does-not-match-the-assembly-reference) and msdn.blog link in accepted answer. – f14shm4n Feb 02 '15 at 21:35
  • I`m using Visual Studio 2013. Newtonsoft.Json not mentioned on MSDN, in the description of the method, now I installed JSON.net package via nuget, but get the same exeption. – Aminion Feb 02 '15 at 21:50

2 Answers2

0

Check if the references to "System.Net.Http", "System.Net.Http.Formatting" and Newtonsoft.Json have Copy Local set to True. On my Visual Studio 2013, when I added a reference to System.Net.Http, the default for Copy Local was false.

You could instead use nuget to add the package for System.Net.Http and Json.Net. I didn't find a nuget package for System.Net.Http.Formatting.

mcdon
  • 4,648
  • 3
  • 34
  • 36
  • I find Microsoft.Net.Http in nuget, and install it, after that, it worked. A little unclear, but the problem is solved. – Aminion Feb 02 '15 at 22:10
  • 1
    The System.Net.Http was likely built using a different version of Newtonsoft.Json, which had a different [stong name](https://msdn.microsoft.com/en-us/library/wd40t7ad%28v=vs.110%29.aspx). When you add the package for [Newtonsoft.Json Nuget adds assembly binding redirects](http://james.newtonking.com/archive/2012/04/04/json-net-strong-naming-and-assembly-version-numbers). A better description of Assembly Binding Redirects is [here](https://msdn.microsoft.com/en-us/library/7wd6ex19%28v=vs.110%29.aspx). You use it to point strong named assembly references to newer versions of those assemblies. – mcdon Feb 02 '15 at 23:25
0

"Newtonsoft.Json" is an assembly from the JSON.NET Nuget Package. Follow the steps in the answer to this question.

After successfully installing the package, you can add a reference to Newtonsoft.Json, just as you did for "System.Net.Http".

Community
  • 1
  • 1
Michael
  • 419
  • 3
  • 11
  • Reference to Newtonsoft.Json was added automatically when I install package. Still same exception. – Aminion Feb 02 '15 at 22:02