我得到了错误

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>

它也没有起作用


当前回答

将正确的版本部署到CI机器

这是在告诉你,程序集加载器找到了一个不同版本的Newtonsoft。Json程序集,它与您在项目中创建的引用不匹配。要正确加载程序集,必须将程序集与已编译的代码并排部署,或者在目标计算机(即GAC)中安装程序集的正确版本。

替代方案:确保配置在正确的文件中

如果要保留当前解决方案,并加载具有不同版本的程序集,请确保您发布的配置位于正确的.config文件中。请记住,没有xpto.dll。config,应用程序加载的DLL总是使用运行应用程序的配置文件。

其他回答

下面的部分添加到您的web.config

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

我犯了一个错误,为。net 4.5添加了一个NewtonSoft .dll文件。

我的主要项目是4.5,但当我向我的解决方案添加一个额外的项目时,它奇怪地将它添加为。net 2.0项目……当我试图使用NewtonSoft的4.5 dll时,我得到了这个“NewtonSoft”。Json cannot 't be found”错误。

解决方案(当然)是将这个新项目从。net 2.0改为4.5。

如果错误在本地消失,仍然出现在服务器上,与我一起工作的解决方案是删除bin文件夹和包。配置和web。配置并重新加载这些文件

我也遇到了同样的错误,为此纠结了好几个小时。我有一个使用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>
<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="7.0.0.0"/>
  </dependentAssembly>
</assemblyBinding>

为我工作....只需将你正在使用的版本放在newVersion中,即(newVersion="7.0.0.0")