我得到了错误

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-12.0.0.0" newVersion="12.0.0.0" />
            </dependentAssembly>
        </assemblyBinding>
    </runtime>

其他回答

uninstall-package newtonsoft.json -force
install-package newtonsoft.json

对我来说是这样的:)

另一个潜在的问题是,如果元素在任何其他dependentAssembly元素上有不正确的配置,那么绑定重定向似乎就会无声地失败。

确保每个元素下只有一个元素。

在某些情况下,VS生成这个:

  <dependentAssembly>
    <assemblyIdentity ...
    <assemblyIdentity ...
  </dependentAssembly>

而不是

  <dependentAssembly>
    <assemblyIdentity ...
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity ...
  </dependentAssembly>

我花了很长时间才意识到这就是问题所在!

我认为你指向错误的目标,把它改为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>

这应该有用。

对我来说,问题是一个贬值版的Newtonsoft.Json。重新安装也无济于事。

在Visual Studio中,进入工具->管理NuGet包。选择更新。搜索Newtonsoft。单击Update安装最新版本。

在我的案例中,在下载程序集并将引用添加到项目后,我通过在将引用添加到项目之前“解锁”DLL来解决这个问题。

使用Windows资源管理器,浏览到DLL位置,右键单击DLL,然后选择“属性”。您将在其中一个选项卡上找到一个“unblock”按钮,然后您可以添加引用,程序集将正确加载。