简体   繁体   English

为什么添加Microsoft.Extensions.Logging原因无法加载文件或程序集System.Net.Http version = 4.2.0?

[英]Why does adding Microsoft.Extensions.Logging cause could not load file or assembly System.Net.Http version=4.2.0?

I started getting from a new .Net 4.6.2 Unit Test project. 我开始从一个新的.Net 4.6.2单元测试项目中获取。 It was really strange so I set out to reproduce with a simplified project which I've put on Github and attached. 真的很奇怪,所以我开始使用我放在Github上并附加的简化项目进行复制。 Unzip and run Nuget restore in VS. 解压缩并在VS中运行Nuget restore。 There are 2 commits. 有2次提交。 The first has it failing and the 2nd has it fixed after removing the " Microsoft.Extensions.Logging.Abstractions " and Microsoft.Extensions.Logging NuGet packages. 在删除“ Microsoft.Extensions.Logging.Abstractions ”和Microsoft.Extensions.Logging NuGet程序包后,第一个失败,第二个已修复。 Adding that package back in will cause the tests to fail. 重新添加该程序包将导致测试失败。

Please help me understand this strange issue. 请帮助我理解这个奇怪的问题。 Does it have something to do this package being from .Net Standard? 它是否有某些功能可以从.Net Standard进行打包? System.Net.Http is coming from .NET Core + Platform Extensions, according to apisofnet , but I'm not using .Net Core. 根据apisofnet的说法System.Net.Http来自.NET Core +平台扩展,但是我没有使用.Net Core。

What can I do continue using System.Net.Http version 4.0.0.0? 我可以继续使用System.Net.Http 4.0.0.0版做什么? Build output has: Unified primary reference "System.Net.Http, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a". 构建输出具有:统一的主要参考“ System.Net.Http,Version = 4.2.0.0,Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a”。

Update Note: I ran through this same exercise of removing Nuget packages from my first commit and the tests didn't pass, so all of this may be a red herring. 更新说明:我进行了相同的练习,即从第一次提交中删除了Nuget软件包,并且测试未通过,因此所有这些可能都是麻烦的。 The screenshots below show that I was successful one time anyways. 下面的屏幕截图显示我无论如何都成功了。

Update 2: I reproduced it with commits step by step: https://github.com/aligneddev/UseSystemNetHttpReferencing/commits/reproduce . 更新2:我一步一步地复制了它: https : //github.com/aligneddev/UseSystemNetHttpReferencing/commits/reproduce I removed all packages, then after removing the last one Microsoft.Extensions.DependencyInjection.Abstractions - system.Net.http is missing build error. 我删除了所有软件包,然后删除了最后一个Microsoft.Extensions.DependencyInjection.Abstractions-system.Net.http缺少生成错误。 I then added in the reference with ReSharper and the unit test passes! 然后,我使用ReSharper添加了参考,并且单元测试通过了!

Last Update: downgrading to .Net 4.5.2 solves the problem as well. 最后更新:降级到.Net 4.5.2也解决了该问题。 I don't really want to do that :-). 我真的不想要这样做:-)。

失败 通过

Adding binding redirection in app.config of UseSystemNetHttp.Test project fixes your issue: UseSystemNetHttp.Test项目的 app.config中添加绑定重定向可解决您的问题:

<?xml version="1.0" encoding="utf-8"?>
<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>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 "无法加载文件或程序集 System.Net.Http 版本 4.1.1.0" - Could not load file or assembly System.Net.Http version 4.1.1.0 无法加载文件或程序集&#39;System.Net.Http,版本= 4.2.0.0系统找不到指定的文件 - Could not load file or assembly 'System.Net.Http, Version=4.2.0.0 The system cannot find the file specified 无法加载文件或程序集&#39;System.Net.Http,Version = 4.1.0.0 .net framework 4.6 .net standard 1.3 - Could not load file or assembly 'System.Net.Http, Version=4.1.0.0 .net framework 4.6 .net standard 1.3 无法加载文件或程序集&#39;System.Net.Http,Version = 4.1.1.1 .Net Standard - Could not load file or assembly 'System.Net.Http, Version=4.1.1.1 .Net Standard 无法加载文件或程序集&#39;System.Net.Http&#39; - Could not load file or assembly 'System.Net.Http' 无法加载文件或程序集 System.Net.Http 4.2.0.0 - could not load file or assembly System.Net.Http 4.2.0.0 无法加载文件或程序集&#39;System.Net.Http - Could not load file or assembly 'System.Net.Http 无法使用单声道加载文件或程序集 System.Net.Http - Could not load file or assembly System.Net.Http using mono Azure失败无法加载文件或程序集&#39;System.Net.Http,版本= 4.2.0.0 - Azure failing Could not load file or assembly 'System.Net.Http, Version=4.2.0.0 System.Net.Http - 无法加载文件或程序集,然后无法加载要执行的引用程序集 - System.Net.Http - Could not load file or assembly, then Cannot load a reference assembly for execution
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM