Reputation: 4066
In my MVC 4 Web API project stops working. It's can't find Newtonsoft.Json. After running this code :
Dim response As HttpResponseMessage = MyHttpClient.PostAsJsonAsync("Api/Test", MyObject).Result
I get message error :
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)
I know that MS is using this as the default JSON serializer now - and it’s referenced. I tried to update Newtonsoft.Json from NuGet but I can't find it; I find "Json.Net". So I used package manager console to reinstall
Update-Package Newtonsoft.Json –Reinstall
But still doesn’t work. Does anyone have any idea why is this going wrong?
Upvotes: 2
Views: 2005
Reputation: 1039368
It seems that you are using some outdated library that depends on an old version of JSON.NET. You could try to install the specific version of it:
Update-Package Newtonsoft.Json -Version 4.5.11
If this fails telling you that some other package requires a newer version of JSON.NET then you will need to resolve this conflict by upgrading the outdated library that you are using and which depends on JSON.NET 4.5
Upvotes: 2
Reputation: 2435
Try to add this section in your web.config file inside <runtime><assemblyBinding>
:
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed" />
<bindingRedirect oldVersion="0.0.0.0-4.5.0.0" newVersion="4.5.0.0" />
</dependentAssembly>
Upvotes: 2