与Newtonsoft.Json的装配冲突

时间:2013-10-07 13:09:48

标签: .net json.net .net-assembly

我需要加载2个版本的程序集Newtonsoft.Json vesion 4.0.8.0和4.5.0.0 现在在我的配置文件中:

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

但我需要旧4.0.8.0和新的4.5.0.0

  <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.8.0" newVersion="4.5.0.0" />
      </dependentAssembly>

我从Package Console安装了最新版本,但它给了我错误:

错误80无法加载文件或程序集“Newtonsoft.Json,Version = 4.5.0.0,Culture = neutral,PublicKeyToken = 30ad4fe6b2a6aeed”或其中一个依赖项。定位的程序集的清单定义与程序集引用不匹配。 (HRESULT异常:0x80131040)

2 个答案:

答案 0 :(得分:33)

我今天遇到了这个问题,我在link找到了解决方案。

基本上更新Newtonsoft.Json包。并在web.config中注册此程序集

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

答案 1 :(得分:7)

将SignalR安装到我的项目后,我遇到了同样的问题。 首先我更新到最新版本的Newtonsoft.Json,然后我将dependentAssembly添加到我的web.config中。但是我必须在新版本中加入6.0.0.0的值,即使在我的软件包中我声明了6.0.8版本。     

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