2021-10-26

【已解决】Could not load file or assembly ‘System.Net.Http, Version=xxx, Culture=neutral…

文章标签: C# System.Net.Http

系统开发完进行生产环境测试时出现错误:

英文版:
Could not load file or assembly ‘System.Net.Http, Version=4.1.1.2, 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)

中文版:
未能加载文件或程序集“System.Net.Http, Version=4.1.1.2, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a”或它的某一个依赖项。找到的程序集清单定义与程序集引用不匹配。 (异常来自 HRESULT:0x80131040)

解决
在 Microsoft Visual Studio 中双击打开System.Net.Http.dll,再双击打开1 [非特定语言]:
2021-10-262021-10-26

在启动项目的web.config或app.config中添加以下配置

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

完整结构:

<configuration>  
   <runtime>  
      <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">  
        <dependentAssembly>
            <assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-4.2.0.0" newVersion="4.0.0.0" />
        </dependentAssembly>
      </assemblyBinding>  
   </runtime>  
</configuration> 

这里使用了 版本重定向
————————————————
版权声明:本文为CSDN博主「onc-virn」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_32682301/article/details/113246247

上一篇:.net core 3.0中动态卸载|卸载程序集


下一篇:App.config配置,实现assembly绑定