我得到了错误

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>

它也没有起作用


当前回答

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的版本。Json Newtonsoft属性

然后你需要在你的web配置中添加这个版本(在我的例子中是8.0.0.0) 网络配置

移除牛顿软。Json程序集从项目引用并再次添加它。您可能不小心删除或替换了dll。

另外,在使用NuGet还原的CI环境中,确保没有将部分文件夹检入源代码控制。默认情况下,在向源代码控制添加文件夹时,它将自动排除程序集。此外,这违背了在构建时恢复核包的整个目的。检查程序集或不检入任何包文件夹都将获得成功的构建,但更好的实践是不将包检入源代码控制。

下面的部分添加到您的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>

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

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

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