我得到了错误

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>

它也没有起作用


当前回答

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

其他回答

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

我得到了同样的错误,并通过添加以下代码错误解决了生产。

回答这个问题已经太迟了,但也许能帮到别人。

    <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
            <dependentAssembly>
                <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
                <bindingRedirect oldVersion="0.0.0.0-12.0.0.0" newVersion="12.0.0.0" />
            </dependentAssembly>
        </assemblyBinding>
    </runtime>

这是非常古老的,似乎仍然有许多人有同样的问题。所以我想分享我的经验,它可能会帮助别人。

我在两个地方也有同样的问题。在一个项目中使用6.0.4.0,在不同的项目中使用4.5.0.0。

1-这对我很有用。在bin文件夹中,我有6.0.0.0 Newtonsoft.Json.dll和到4.5.0.0 dll的符号链接

<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<probing privatePath="bin\4.5dlls-path;" />
<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>

如果你不知道如何在这里创建符号链接。

mklink /D "文件夹名称" " dll路径"

2-在这种情况下,当我从Web配置文件中删除部分时,它工作了。记住,我在不同的项目中参考了6.0.0.0和4.5.0.0。在符号链接中,我有12.0.1.0 dll和6.0.0.0 bin。

<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<probing privatePath="bin\12.0.1dlls-path;" />
</dependentAssembly>
</assemblyBinding>
</runtime>

3-我还有一个解。如果您在不同的项目中有不同版本的Newtonsoft.Json.dll,请尝试将所有版本升级到一个版本或最新版本,但在某些情况下可能无法工作。system.net.http.formating.dll可能需要netttonsoft . json .dll 6.0.0.0版本。在这种情况下,你需要6.0.0.0的版本,所以尽量让所有的版本都相同。希望这能帮助到一些人。

答案从2022年开始。 得到类似的异常错误:

Could not load file or assembly 'Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'

解决办法是进入网络。配置文件的项目,并进行以下编辑:

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

我正在写一个WebApi REST服务客户端,所以对我来说,这个错误是由通过添加引用手动添加System.Net.Http和System.Net.Http. formatting程序集引起的,而我应该通过NuGet添加Microsoft.AspNet.WebApi.Client包。 另见另一个问题的答案。