我得到了错误

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>

它也没有起作用


当前回答

你应该更新网页。配置文件在服务器。 当nuget安装NewtonSoft更新这个文件,包括这个代码

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

其他回答

你可以从引用中的属性中找到你的库的安装版本。对于我的情况,我安装了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>

致所有使用牛顿软体有问题的人。Json v4.5版本尝试在web中使用这个。Config或app.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>

重要提示:检查配置文件的配置标记是否没有命名空间属性(如https://stackoverflow.com/a/12011221/150370中建议的那样)。否则,assemblyBinding标记将被忽略。

我通过安装Nuget包解决了这个问题:Microsoft ASP。NET Web API 2.2客户端库。这反过来安装了newtonsoft。Json版本6.04

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

你应该更新网页。配置文件在服务器。 当nuget安装NewtonSoft更新这个文件,包括这个代码

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