在IIS上无法加载文件或程序集'System.Net.Http, Version=4.2.0.0, Culture=neutral'。

6

我开始更新一些NuGet包,构建时出现了System.Net.Http冲突的警告。根据这里的建议:

关于System.Net.Http 4.2.0.0无法找到的奇怪问题

我将所有对System.Net.Http的引用替换为NuGet版本,而不是Visual Studio捆绑的版本。然后我按照各处建议更改了所有重定向绑定(app.config和web.config),在本地得到了工作。但是...

当我部署到我们的测试服务器时,仍然会出现错误

Could not load file or assembly 'System.Net.Http, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

我正在使用Net 4.7.0和Visual Studio 2017。
我搜索了所有的配置文件,但没有找到关于版本4.2.0.0的任何信息。为什么IIS认为它需要这个版本?
我的System.Net.Http的Nuget版本是4.3.4,但实际的web.config文件有这些行。
<dependentAssembly>
   <assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
   <bindingRedirect oldVersion="0.0.0.0-4.1.1.3" newVersion="4.1.1.3"/>
</dependentAssembly> 

我可以在本地构建和运行它,但我的服务器报告了错误。

更新:我尝试在服务器的web.config中添加此内容。

 <dependentAssembly>
    <assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-4.2.0.0" newVersion="4.1.1.3" />
  </dependentAssembly>

这样就能消除错误!但我仍然不明白为什么需要这样做?我的服务器为什么要使用4.2.0版本?


同意,我也遇到了同样的问题。我把“bindingRedriect”更新为与你的相同,它就开始工作了。 - dev
3个回答

2

我将解决方案更新到了.NET Framework 4.7.2,并确保服务器安装了这个版本。这解决了我的问题。之后,我可以删除绑定重定向。


1
<bindingRedirect oldVersion="0.0.0.0-4.2.0.0" newVersion="4.2.0.0" />

如果您无法安装.net 4.7,请在web.config中删除此行。

0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接