'Assembly 'System.Web.Http, ...' uses 'Newtonsoft.Json, Version=6.0.0.0...' which has a higher version than referenced assembly

I'm getting the following error when I Rebuild my project.

Assembly 'System.Web.Http, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' uses 'Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' which has a higher version than referenced assembly 'Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'    D:\Development\MyProject\bin\System.Web.Http.dll

I have already uninstalled and installed the latest version of Newtonsoft.Json (9.0.1) using Manage NuGet Packages in VS 2013. Why is it still referencing version 6.0.0.0 (or is it 4.5.0.0)?

My web.config shows the following:

<dependentAssembly>
   <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral"/>
   <bindingRedirect oldVersion="0.0.0.0-4.5.0.0" newVersion="4.5.0.0"/>
</dependentAssembly>

What else should I do to resolve this? Thanks.



Solution 1:[1]

I encountered similar problems with newtonsoft.json reference after installing the nuget package Microsoft.AspNet.WebApi.Owin in combination with Microsoft.Owin.Security.OAuth package. I resolved the problem by running the following commands in the nuget package manager

First, uninstall the newtonsoft.json

uninstall-package Newtonsoft.Json -Force

Then, install the latest newtonsoft.json

install-package Newtonsoft.Json

And finally, update the owin OAuth which seems to be referencing to the old newtonsoft.json version

update-package Microsoft.Owin.Security.OAuth

After this, build the project and it should compile..At least my did :)

Solution 2:[2]

I managed to resolve this by going into web.config and changing this:

<dependentAssembly>
    <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
  <bindingRedirect oldVersion="0.0.0.0-4.5.0.0" newVersion="4.5.0.0" />
</dependentAssembly>

to this:

<dependentAssembly>
    <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="9.0.0.0" />
</dependentAssembly>

I'm not sure why the "newVersion" should be 9.0.0.0 when my Newtonsoft.Json version is 9.0.1, but it didn't compile with the latter.

Interestingly, when I later entered the following in the Package Manager Console:

Update-Package Newtonsoft.Json -Version 9.0.1

I could change the "oldVersion" and "newVersion" to anything and it had no effect on the compilation.

Many thanks to Rajput, Marcus H and Vivek Nuna for your help.

Solution 3:[3]

I don't know if you still need this or not. After updating Newton.Json in my project, your kind of error happens. And I found this thread and follow all answer instruction but no luck. But when I remove Newton.Json from references, then add my newer version of Newton.Json.dll to references, it works!

remove reference

Solution 4:[4]

I've just had this issue, and spent way too much time fixing it.

What clinched it for me was realising that the publish stage of my API didn't publish the web.config in the root folder of the API, but in the bin folder.

Moving the web.config to the root fixed the issue as IIS can then set up the API correctly, rather than falling back to host/machine configs (which don't include the rebinding instructions)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Marcus Höglund
Solution 2 Windhoek
Solution 3
Solution 4 0xFF