【问题标题】:Assembly Conflict with Newtonsoft.Json与 Newtonsoft.Json 的装配冲突
【发布时间】:2013-10-14 01:57:45
【问题描述】:

我需要加载 2 个版本的程序集 Newtonsoft.Json 版本 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>

我从包控制台安装了 Newtonsoft - 最新版本 - 但它给了我一个错误:

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

【问题讨论】:

  • 我检查了 JSON.net NuGet 发布信息,但我找不到发布 4.5.0.0 nuget.org/packages/newtonsoft.json 此外,如果您已经拥有最新版本的库,您需要使用旧版本?
  • 为什么我记得在 nuget 之前一切都变得如此简单?

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


【解决方案1】:

我今天遇到了这个问题,我在这个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>

【讨论】:

  • 你从哪里得到 publicKeyToken?
  • 当我尝试构建我的应用程序时,我在错误列表控制台中获得了 publicKeyToken,因此我复制了它,但这是获得它的另一种方式stackoverflow.com/questions/1710935/… 如果您的网络中有其他参考。 config,您可能会注意到它们是相等的,因此您可以从另一个程序集中复制令牌。
  • 这有点乱,但我最终让它工作了。首先,我将我的项目从 Newtonsoft 9.x 更新到 12.0.2。没有运气。然后我回到 9.x 并重新启动 VS。不去。然后我又从 9.x 升级到 12.0.2。不去。然后我从 12.0.2 转到 12.0.1,然后它工作了。 /眼珠。至少它现在正在工作。
【解决方案2】:

将 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>

【讨论】:

  • 这适用于我的版本 8.0.3。直到我将 newVersion 更改为 8.0.0.0,它才起作用。
  • 刚刚用 12.0.1 试过这个。我将其更改为版本 12.0.0.0 并解决了该问题。谢谢!
猜你喜欢
  • 2020-06-24
  • 2017-02-09
  • 1970-01-01
  • 2013-07-20
  • 2016-01-11
  • 2016-02-29
  • 2019-01-10
  • 1970-01-01
  • 2019-08-29
相关资源
最近更新 更多