Newtonsoft.json assembly package version mismatch

微笑、不失礼 提交于 2019-11-27 09:01:50

Found solution, try with:

<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
        <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>
    </assemblyBinding>
</runtime>

You can modify assembly-binding configuration and add a redirect. See Redirecting Assembly Versions on MSDN.

Basically you want to add following snippet to your app.config or web.config file:

<configuration>
   <runtime>
     <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
       <dependentAssembly>
         <assemblyIdentity name="Newtonsoft.Json"
                           publicKeyToken="30ad4fe6b2a6aeed"
                           culture="neutral" />
         <!-- 
           Assembly versions can be redirected in application, 
           publisher policy, or machine configuration files.
         -->
         <bindingRedirect oldVersion="1.0.0.0-4.5.11.0" newVersion="4.5.11.0"/>
       </dependentAssembly>
     </assemblyBinding>
   </runtime>
</configuration>

EDIT

Why do you need to redirect assembly versions? Even though SocketIO4Net supports newer versions of Newtonsoft.Json, it was compiled against a single version (4.0.8 in your case). This version is stored in the DLL and it is used to load DLLs SocketIO4Net depends on.

Note that NuGet dependencies are not the same as DLL/runtime dependencies - NuGet dependency on Newtonsoft.Json >= 4.0.8 only means that you will be allowed to install SocektIO4Net into a project that has a newer version of Newtonsoft.Json, it has nothing to do with runtime settings.

That being said, recent NuGet versions should add assembly-binding-redirects automatically for you if your project has app.config or web.config file.

The above solutions are correct but there is one more point that should not be forgotten: the app.config content was the same as the above solutions.

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

But it's a good idea to check if it's up to date. In my case, Newtonsoft.JSON (v.6.0.4) has come to depend on another package.

There are two option;

  1. Update (Newtonsoft.JSON package) last versions.
  2. Update app.config file in the version numbers.

And last advice, if you are working with more than one project, eg. exe-dll and check both versions if there is Newtonsoft.JSON.

Put in an assembly redirect in your app/web.config;

   <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" PublicKeyToken="30ad4fe6b2a6aeed" />
        <bindingRedirect oldVersion="1.0.0.0-4.5.11.0" newVersion="4.5.11.0" />
      </dependentAssembly>

Please note the versions numbers need to match the version you have installed.

Had this same issue.

Just resolved it.

It happened after NuGet was used to install Ext.NET which has a dependency for Newtonsoft.JSON.
There was already a Newtonsoft.JSON.dll file in /bin (and obviously a reference to it in the web.config file) folder without checking I started the NuGet Package-Install procedure while debugging(so the file probably had a lock).

On the runtime error window it will tell you on the stack trace what part of the manifest it has a problem with, mine was major version so I checked the install package version. and it was 1 major version out. Found the original NuGet file under: "[physical path]/../packages/Newtonsoft.Json.[version]/lib/[.net version]/"

Both Manifest and Library was there so copied it into /bin folder, updated the root web.config assembly information and it worked.

Code samples: Before

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

After

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

Hope this helps

In my case, I removed the package with NuGet and installed a fresh one. Then, remove the reference from References and add again manually. Works like charm. Hope resolve for you.

I was working on an old project recently. I needed to update our Newtonsoft.Json.dll, since I had to utilize a "new" API which required a newer version, but I still had other DLLs that required the old version.

bindingRedirect you say? Nope. It kept complaining about the manifest mismatch.

Separate codeBase tags? Nope. It kept complaining about the manifest mismatch.

The problem was, apparently, that the old version of Newtonsoft.Json.dll (3.0.0.0) does NOT have a PublicKeyToken, but the "new" version (4.5.7.1) DOES have a PublicKeyToken. Therefore they couldn't share the same dependentAssembly-tag.

This is what I ended up with:

<dependentAssembly>
    <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="" culture="neutral"/>
    <codeBase version="3.0.0.0" href="bin\Newtonsoft_Old\Newtonsoft.Json.dll" />
</dependentAssembly>
<dependentAssembly>
    <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral"/>
    <codeBase version="4.5.0.0" href="bin\Newtonsoft.Json.dll" />
</dependentAssembly>

Got the above Error: in Visual Studio 2013 To Fix: In package mamnager Execute: Install-package newtonsoft.json This will add a new line in packages.config <package id="Newtonsoft.Json" version="6.0.5" targetFramework="net45" /> Remove the previous line which might point to previous version on packages.config. Delete the old version's directory on the packagers directory. Remove the reference of NewtonSoft.Json and readd it pointing to the latest version. Root webconfig will have the following <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" /> once everything is done. Close and reopen visual studio. This should fix it. I had the same error when installing PM> install-package durandal.starterkit I used the above method to fix.

Just had this happen with TeamCity and I imagine others will soon experience this. This probably applies to most build servers that pull NuGet packages.

All the answers that say to do redirects are correct. However, you need to still define the correct version number. My project was using Newtonsoft.Json 7.0, however, they had just released 8.0 and TeamCity was pulling down 8.0 which was causing issues only on the server and not locally. All my redirects were set to 7.0.

Make sure that the deployed application is actually getting the correct version from NuGet and not just the latest and greatest. Or update your config to point to the newest version.

Kristóf Turánszki

Other solutions didn't work for me. Although I had different nuget package (Newtonsoft.Json.Schema version=3.0.0.0).
So my project was an ASP .NET project and the Newtonsoft.Json.Schama package was referred in a .NET Standard project. The solution was simply to add the Nuget package to the WEB (or startup) project too, and the problem disappeared.

I have fixed this issue easily: I had not copied the xml configuration file from the compilation folder.

I just made sure that the xml configuration file was also included along with my program and everything worked fine!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!