Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I fix assembly version conflicts with JSON.NET after updating NuGet package references in a new ASP.NET MVC 5 project?

I created a new ASP.NET MVC 5 web project in VS 2013 (Update 1) then updated all NuGet packages. When I build the project, I get the following warning:

warning MSB3243: No way to resolve conflict between "Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed" and "Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed".

When I check the web.config, however, I see that a binding redirect is in place:

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

Which is exactly what the warning advises.

How can I fix this warning?

like image 935
Jim Lamb Avatar asked Feb 01 '14 12:02

Jim Lamb


People also ask

What is Newtonsoft JSON NuGet?

Json.NET is a popular high-performance JSON framework for .NET. Product. Versions. .NET. net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows.


1 Answers

Here the steps I used to fix the warning:

  • Unload project in VS
  • Edit .csproj file
  • Search for all references to Newtonsoft.Json assembly
    • Found two, one to v6 and one to v5
    • Replace the reference to v5 with v6
  • Reload project
  • Build and notice assembly reference failure
  • View References and see that there are now two to Newtonsoft.Json. Remove the one that's failing to resolve.
  • Rebuild - no warnings
like image 67
Jim Lamb Avatar answered Sep 27 '22 23:09

Jim Lamb