1
votes

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)

2
What IDE? Did you check the libraries' locations and expected locations? - D. Ben Knoble
Do you have the Newtonsoft.Json dependency? - Luminous
Check this link and msdn.blog link in accepted answer. - f14shm4n
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

2 Answers

0
votes

"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".

0
votes

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.