Alex T
Alex T

Reputation: 765

The type 'JsonConvert' exists in both 'Newtonsoft.Json ver 9 and 10

I am constantly plagues by issues where Newtonsoft.Json seems to be available in multiple versions within my project. The problem is that it is not. I have 10 installed in the project, and that's the only DLL that's in place. The GAG does not have the dll, and the web.config seems correct.

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

Has anyone else seen this? Is there a way to specify the version to use at code level, or within the web.config?

Upvotes: 9

Views: 11582

Answers (3)

AaronHolland
AaronHolland

Reputation: 1675

This seems to be due to multiple invisible references to the Newtonsoft.Json DLL

  1. Right click on your project and select Unload Project.
  2. Now right click again and select Edit MyProject.csproj (or whatever your project is called)
  3. Search for Newtonsoft.Json within this file.
  4. If you find multiple Reference elements with different versions, delete all but the newest version
  5. Save the file
  6. Right click on your project again and select Reload Project

The errors should be gone.

Upvotes: 30

mustafatorun
mustafatorun

Reputation: 324

try install previous version of newtonsoft.json

in my circumstance, I updated newtonsoft to 11.0.2 from 6. Compiling gave this error message that include ver 6 and 11. I tried uninstall, but i did not, cause of dependencies. but I used this command and I succeded to downgrade. Install-Package Newtonsoft.Json -Version 11.0.1

and this error gone.

Upvotes: 10

Patrick Hofman
Patrick Hofman

Reputation: 156978

You should force to load only one assembly, I suggest to load the latest one. You can check if all referenced assemblies use that version. If not, you have to add this to your web.config file:

<runtime>
  <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <dependentAssembly>
      <assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed" />
      <bindingRedirect oldVersion="0.0.0.0-10.0.0.0" newVersion="10.0.0.0" />
    </dependentAssembly>
  </assemblyBinding>
</runtime>

This will force to use version 10 of Newtonsoft.Json. Make sure to remove version 9 from the bin folder.

Upvotes: 3

Related Questions