我得到了错误

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包解决了这个问题:Microsoft ASP。NET Web API 2.2客户端库。这反过来安装了newtonsoft。Json版本6.04

其他回答

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

\Newtonsoft.Json.6.0.5\…

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

我修复了添加这个绑定重定向到我的.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,而不是相反

看看Newtonsoft的版本。Json Newtonsoft属性

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

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

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