我得到了错误

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选项必须强制卸载。与其他程序集的依赖关系阻止在没有它的情况下卸载。

其他回答

我们遇到了你提到的同样的问题。我们正在使用nunit通过CI运行测试,并且我们让nunit运行一个名为tests的文件。Nunit,它描述了要运行的测试DLL fixture的列表。

每个测试装置都有自己的配置文件,但是当运行“测试。绑定重定向的Nunit文件似乎被忽略了。解决方案是将绑定重定向添加到新的配置文件“tests”。测试旁边的“配置”。nunit”文件。

你可以从引用中的属性中找到你的库的安装版本。对于我的情况,我安装了8.0.0.0。错误提示无法加载文件或程序集'Newtonsoft。Json,版本=6.0.0.0,文化=中性,PublicKeyToken=30ad4fe6b2a6aeed'或其依赖项之一。

所以我必须在web.config中手动添加以下内容

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

关于这个开放性话题,还有一个建议。运行“分析”后出现错误:项目设置中发生了更改。问题是:

项目/设置/构建/平台目标

显示“任意CPU”。

设置回x86(或者在您的情况下可能是x64)解决了这个问题。

我修复了添加这个绑定重定向到我的.config文件的问题:

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

错误消息抱怨找不到版本4.5.0.0,当前版本的Newtonsoft。Json是6.0.0.0,所以重定向应该从4.5到6.0,而不是相反

我认为你指向错误的目标,把它改为4.5而不是6.0

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

这应该有用。