2

I have started a new Web Application in Visual Studio 2019. I have added a Web Api. Shortly after or at the same time (can't remember), I startet getting warnings like this:

Warning     No way to resolve conflict between "Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed" and "Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed". Choosing "Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed" arbitrarily.

I noticed but did not do anything as I decided to wait until it gave me problems.

And that is now...

I am about to use a JSon object but when writing this:

JObject jObject = JObject.Parse(result);

The compiler gives me this error:

Error   CS0433  The type 'JObject' exists in both 'Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' and 'Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'

I have searched the web and my conclusions are as follows:

  • It looks like it is Microsoft.AspNet.WebApi.Client that is the only package installed, that has a dependency on Newtonsoft.Json (>= 6.0.4)
  • I have installed Newtonsoft.Json (12.0.3)
  • In Solution Explorer. In reference list, I have only 1 reference. And that is the one for 12.0.3.
  • In Web.Config I have this entry (and only this for Newtonsoft.Json).
    • <dependentAssembly><assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30AD4FE6B2A6AEED" culture="neutral"/><bindingRedirect oldVersion="0.0.0.0-12.0.0.0" newVersion="12.0.0.0"/></dependentAssembly>
  • In my .csproj I can see 3 different references in 3 different ItemGroups:
    • One for v. 12.0.0.0
    • One for v. 12.0.2
    • And one for v. 12.0.3
  • I tried to uninstall package Newtonsoft.Json, but is not allowed as other packages are dependent on this.
  • I have runned this command: Update-Package Newtonsoft.Json in the Package Manager Console, which told me, that no new updates were available.

And now, I have runned out of ideas. I am stucked. Anyone knows what to do?

****New update**** I found the 6.0.0.0. Please have a look at the picture:

Here in resources I double clicked the Newtonsoft.Json reference and in the object browser I can see both 6.0.0.0 and 12.0.0.0.

Here in resources I double clicked the Newtonsoft.Json reference and in the object browser I can see both 6.0.0.0 and 12.0.0.0.

As you can see, both 6.0.0.0 and 12.0.0.0 are present. 6.0.0.0 is somewhere on my C:-drive inside a SDK.

I have tried to delete the file. My project got nuts. Then I replaced that file with the 12.0.0.0 from my project. This gave me the error that assemplies did not match.

I finally copied the old .dll back. And is a bit stucked again.

Any ideas?

zorci
  • 145
  • 1
  • 9
  • try to edit the packages.json(s) itself, delete the unwanted version from the packages directory and reload your solution. – Felix D. Feb 19 '20 at 07:35
  • Does this answer your question? [How can I fix assembly version conflicts with JSON.NET after updating NuGet package references in a new ASP.NET MVC 5 project?](https://stackoverflow.com/questions/21498074/how-can-i-fix-assembly-version-conflicts-with-json-net-after-updating-nuget-pack) – Hamed Moghadasi Feb 19 '20 at 07:36
  • Looking in my /packages folder I see only one folder for: "Newtonsoft.Json.12.0.3". Nothing else. :( – zorci Feb 19 '20 at 07:50

3 Answers3

7

Okay, I fixed it.

I had 2 references in my .csproj file to Newtonsoft.Json. One pointed at packages......\xxx.12.0.3 and one pointing at packages......\xxx.12.0.2.

Both of them was above 6.0.0.0 which was the error I got. So I ignored them.

But acutally, in my project I had only 12.0.3 folder and no 12.0.2 folder. So the reference did not work and VS tried to find another place to look.

I guess it looks around, maybe using the GAC but finally it ended up deep down my local drive in one Azure SDK and found Newtonsoft.Json 6.0.0.0. And that was the problem.

I removed the 12.0.2 reference from my .csproj and finally it worked.

zorci
  • 145
  • 1
  • 9
1

The issue usually comes from two different projects that use different versions of the same library.

Both of those projects are then referenced to another one and the warning effectively warns you that something like this might happen.

Go to the solution and right click - manage nuget packages.

Go to the consolidate tab. Check that newtonsoft is there. If it is, install the same package to all projects.

If that doesn't work, check your projects for added references that don't come from a nuget and remove those too.

Athanasios Kataras
  • 25,191
  • 4
  • 32
  • 61
  • Nothing on the Consolidated "tab". It is empty. And the only reference in the reference list is 12.0.3 – zorci Feb 19 '20 at 08:30
  • I have 2 projects - My Web Application project and a test project (generated by Visual Studio - and I have not used it yet). – zorci Feb 19 '20 at 09:26
  • In my case I had a Test project on 4.7.2 and AspNet.Core.5.2.7 dependency was pulling in >6.0.4 but my main project (on 4.6.2) had an explicit reference to 7.0.1. Adding an explicit reference to 7.0.1 on the Test project, AspNet.Core was happy to use it and the conflict was resolved. Nothing to consolidate in the package manager. – 9swampy Sep 29 '21 at 19:20
-1

In my case, I had to edit the .csproj and look for Newton references. I found out that Antlr3 had a HintPath to an old version. Even the package not existing.

Andre RB
  • 306
  • 4
  • 7