我得到了错误

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>

它也没有起作用


当前回答

通常情况下,添加绑定重定向应该可以解决这个问题,但对我来说行不通。经过几个小时的思考,我意识到在我的web.config中有一个xmlns属性导致了问题。从Web中的配置节点中删除xmlns属性后。配置时,绑定重定向按预期工作。

http://www.davepaquette.com/archive/2014/10/02/could-not-load-file-or-assembly-newtonsoft-json-version4-5-0-0.aspx

其他回答

关键是在配置文件中引用正确的版本。

步骤;

1-在项目引用属性中查看你的Newtonsoft.Json.dll的版本是什么,无论你的包文件夹中的版本是什么(例如,我的版本是7.0.1,参考版本是7.0.0.0)

2-看看项目期望从你的异常(我的是6.0.0.0)

3-添加依赖程序集到您的配置文件,因为它应该。

  <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>
uninstall-package newtonsoft.json -force
install-package newtonsoft.json

对我来说是这样的:)

在我的例子中,我的文件夹名为Newtonsoft.Json.6.0.7

\Newtonsoft.Json.6.0.5\…

将.csproj文件更改为6.0.7修复了这个问题。

关闭解决方案。

打开包。Config和*。用csproj文本编辑器删除任意一行都有Newtonsoft。Json

Ex:

<Reference Include="Newtonsoft.Json,Version=9.0.0.0,Culture=neutral,PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
      <HintPath>..\packages\Newtonsoft.Json.9.0.1\lib\net40\Newtonsoft.Json.dll</HintPath>
      <Private>True</Private>
</Reference>

Or

<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net40" />

再次打开解决方案并重新安装Newtonsoft。Json由安装包Newtonsoft。Json

这对我很管用。

我修复了添加这个绑定重定向到我的.config文件的问题:

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

错误消息抱怨找不到版本4.5.0.0,当前版本的Newtonsoft。Json是6.0.0.0,所以重定向应该从4.5到6.0,而不是相反