我得到了错误

fileloadexception:无法加载文件或程序集 “Newtonsoft。Json,版本=4.5.0.0,文化=中性, PublicKeyToken=30ad4fe6b2a6aeed'或其依赖项之一。的 定位程序集的清单定义与该程序集不匹配 参考。(异常来自HRESULT: 0x80131040)

用于我的CI构建

我尝试过的解决方案

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

它也没有起作用


当前回答

我没有运气的任何解决方案在这里(卸载,重新安装,删除引用,创建bindingRedirects等),我不得不回到旧版本的Newtonsoft。版本5.0.6以前可以工作,所以我尝试了这个版本。我必须在包控制台中输入这两个命令:

uninstall-package newtonsoft。json force

安装包newtonsoft。Json -version "5.0.6"

第一个命令中的-force选项必须强制卸载。与其他程序集的依赖关系阻止在没有它的情况下卸载。

其他回答

uninstall-package newtonsoft.json -force
install-package newtonsoft.json

对我来说是这样的:)

updating web.config with the following assembly binding resolved the issue 
<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">     
      <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed"
                culture="neutral" />
        <bindingRedirect oldVersion="4.5.0.0" newVersion="6.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>

我也遇到了同样的错误,为此纠结了好几个小时。我有一个使用Newtonsoft的web API项目。json和另一个UnitTest项目的web API项目。单元测试项目也需要Newtonsoft。json参考。但是在添加链接时,我得到了上面的异常。

我最终通过在单元测试项目的app.config中添加以下代码片段来解决这个问题:

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

在包管理器控制台执行:Update-Package -重装Newtonsoft.Json。

更新

我最初是作为评论发布这篇文章的,但正如@OwenBlacker建议的那样,我就把它放在这里:

如果在这样做之后仍然得到错误,那么最终对我有用的是我删除了Json。Net的<dependentAssembly>节从我的.config文件。重新安装会使它回来,如果它不存在,显然你需要删除它。在包本身有一个正常的解决方案之前,恐怕这个手动步骤是必须的。

注意:在这样做之前,请阅读下面的评论。

根据René下面的评论,请注意,答案中发布的命令将在解决方案中的每个项目中重新安装软件包。如果你用牛顿软体。Json包在几个项目中,可能使用不同的版本,只是执行上面的命令可能会有不想要的后果。

除了这里的许多答案之外,我发现了一些东西,因此添加了它。第一点,确保dll没有从GAC引用。除此之外,

在添加/更改Newtonsoft的dll时。Json,有时*。项目的Csproj不会被更改,否则json DLL的更改版本将不会反映在解决方案的Csproj中。

在notepad++中打开项目,搜索Newtonsoft。并显式地将Json从旧版本重命名为新版本。现在切换回VS后,解决方案/项目将重新加载所需的Newtonsoft版本。JSON dll。