0

I'm using Newtonsoft.Json.JsonConvert but the error is as follows:

The type 'JsonConvert' exists in both 'Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' and 'Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'

Image of the error given enter image description here

Here are the things I did:

  1. I have built the project Build -> Clean then Build -> Rebuild
  2. I right-clicked on the project and Unloaded Project and then Reload Project
  3. I once deleted and reinstalled Newtonsoft.Json

I have done all the above but the problem has not been solved what should be done? I use .net 4.6.1

in web.config (runtime tag)

<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Antlr3.Runtime" publicKeyToken="eb42632606e9261f"/>
        <bindingRedirect oldVersion="0.0.0.0-3.5.0.2" newVersion="3.5.0.2"/>
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35"/>
        <bindingRedirect oldVersion="0.0.0.0-1.1.0.0" newVersion="1.1.0.0"/>
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35"/>
        <bindingRedirect oldVersion="0.0.0.0-1.6.5135.21930" newVersion="1.6.5135.21930"/>
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed"/>
        <bindingRedirect oldVersion="0.0.0.0-12.0.0.0" newVersion="12.0.0.0"/>
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35"/>
        <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0"/>
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35"/>
        <bindingRedirect oldVersion="0.0.0.0-5.2.4.0" newVersion="5.2.4.0"/>
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35"/>
        <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0"/>
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
  • We'll need to know more about the kind of project you're using. Basically you probably need an *assembly binding redirect* from version 9 to version 10... but it's hard to be more specific than that without knowing details about your application. (If you're able to move to an SDK-style project where you can specify NuGet packages as references, that tends to make things much simpler in my experience.) – Jon Skeet May 06 '21 at 17:10
  • Version 9 to Version 12 @JonSkeet – Mohammad Hasan Salmanian May 06 '21 at 17:20
  • 1
    Could be other projects or aseemblies reference Newtonsoft – Jonathan Alfaro May 06 '21 at 17:21
  • What kind of information do you want me to add in the post? @JonSkeet – Mohammad Hasan Salmanian May 06 '21 at 17:21
  • Well you could start by telling us about your application. What kind of application is it? What dependencies do you have (and which versions)? Which version of .NET are you using? What assembly binding redirects to you have at the moment? Are you able to provide a [mcve]? – Jon Skeet May 06 '21 at 17:26
  • I use .net 4.6.1 in Asp.Net MVC and Updated post.@JonSkeet – Mohammad Hasan Salmanian May 06 '21 at 18:19

1 Answers1

1

This happens because your project itself contain a Newtonsoft JSON library with version A and one of the other project it reference also contains Newtonsoft JSON library version B.

Try referencing a single version to both the projects.

You can try

  1. Remove the older one, preferably (from one of the project)
  2. Clean and rebuilt entire solution
  3. Resolve the new references
Sangeeth Nandakumar
  • 1,362
  • 1
  • 12
  • 23