Newtonsoft.json assembly package version mismatch

2019-01-11 22:21发布

I am trying to use SocketIO4Net to create socket.io client in .net. Itseems SocketIO4Net has a dependency of Newtonsoft.Json >= 4.0.8. I also am using PushSharp library which has a Newtonsoft.Json dependency of >= 4.5.10. I got NewtonSoft.Json 4.5.11 when i first installed PushSharp and I thought this version should support SocketIO4Net as well since its a higher version but i get this error whenever am trying to connect to socket.io server.

Could not load file or assembly 'Newtonsoft.Json, Version=4.0.8.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

I have been banging my head all day with these dependency issues, I would be very grateful if someone can point me in the right direction.

10条回答
该账号已被封号
2楼-- · 2019-01-11 23:00

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>
查看更多
再贱就再见
3楼-- · 2019-01-11 23:00

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.

查看更多
Lonely孤独者°
4楼-- · 2019-01-11 23:04

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.

查看更多
太酷不给撩
5楼-- · 2019-01-11 23:07

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>
查看更多
我欲成王,谁敢阻挡
6楼-- · 2019-01-11 23:10

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.

查看更多
beautiful°
7楼-- · 2019-01-11 23:11

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!

查看更多
登录 后发表回答