6

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.

Rajput
  • 2,597
  • 16
  • 29
Windhoek
  • 1,701
  • 1
  • 15
  • 26
  • 1
    Change the reference also – Vivek Nuna Oct 23 '16 at 18:00
  • Are you using web api and owin? – Marcus Höglund Oct 23 '16 at 18:21
  • 1
    try to change newVersion="4.5.0.0" version manually to your latest one in section with new one what you installed and see if this is working – Rajput Oct 23 '16 at 18:43
  • @viveknuna - I went to References > Add Reference > Browse > selected Newtonsoft.Json.dll > Add, but nothing seems to get added and I don't see it under the list of Assemblies or any of the recent assemblies added. – Windhoek Oct 23 '16 at 23:38
  • @MarcusH Yes I'm using web api and owin. I uninstalled and installed them again just to make sure I was using the latest versions. – Windhoek Oct 23 '16 at 23:46
  • @Rajput I made this change in web.config binding redirect to: newVersion="9.0.1.0" But I still get the same error. The error seems to be telling me that System.Web.Http is using the wrong version of Newtonsoft.Json. How do I make it reference the correct version? – Windhoek Oct 23 '16 at 23:46
  • Error is still same ? And what about the original version of newtonsoft thats also not working ? This is completely versioning issue of reference dll, so you need to go with trial method of adding All newtonsoft dll one by one i know this is lengthy task but if you dont have any option then do it. @Windhoek – Rajput Oct 24 '16 at 00:07
  • @Rajput Thanks. I tried putting back the old Newtonsoft dll in the bin folder but get the same error. I don't mind trial method... have been trying different changes for 2 hours. How do I add all Newtonsoft dll? I've gone to References and added, like I described in the comment above. Is that the wrong way? – Windhoek Oct 24 '16 at 01:32
  • Do you have a reference to Microsoft.Owin.Security.OAuth in your project? – Marcus Höglund Oct 24 '16 at 05:27
  • @MarcusH yes I do. Microsoft.Owin.Security.OAuth v3.0.1 is installed as a NuGet package. – Windhoek Oct 24 '16 at 16:34

4 Answers4

9

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 :)

Marcus Höglund
  • 16,172
  • 11
  • 47
  • 69
  • Thanks for the suggestion. I tried that but I still get the same build error. From the error message, it seems to be complaining that 'System.Web.Http' is trying to use Newtonsoft.Json version 6.0.0.0 (I'm using 9.0.1), and that the 'referenced assembly' is 4.5.0.0. How do I change the Newtonsoft.Json that System.Web.Http is using, and the assembly reference? – Windhoek Oct 25 '16 at 02:04
  • Ok, Worth a try,. have you looked at these answers http://stackoverflow.com/questions/12027543/visual-studio-2012-web-api-project-wont-run-cant-find-newtonsoft-json – Marcus Höglund Oct 25 '16 at 06:06
  • yes I did. Unfortunately they don't work. How would I install 'System.Web.Http'? I can't seem to find it in NuGet. – Windhoek Oct 25 '16 at 17:26
  • I would start over and unistall all packages and then adding them one by one and control where the error exist. The System.Web should else be under Microsoft.AspNet.WebApi.Owin – Marcus Höglund Oct 25 '16 at 19:05
3

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.

Windhoek
  • 1,701
  • 1
  • 15
  • 26
1

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

purnadika
  • 282
  • 2
  • 12
0

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)

0xFF
  • 86
  • 5