System.Net.Http NuGet包4.3.0参考在System.Diagnostics.DiagnosticSource ver 4.0.0.0参考上生成System.IO.FileLoadException [英] System.Net.Http NuGet package 4.3.0 reference generates System.IO.FileLoadException on System.Diagnostics.DiagnosticSource ver 4.0.0.0 reference

查看:226
本文介绍了System.Net.Http NuGet包4.3.0参考在System.Diagnostics.DiagnosticSource ver 4.0.0.0参考上生成System.IO.FileLoadException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题描述:

共享库"shared.dll"项目引用System.Net.Http NuGet包4.3.0.引用"shared.dll"的应用程序失败

A shared library "shared.dll" project references System.Net.Http NuGet package 4.3.0. The application that references "shared.dll" fails with

System.IO.FileLoadException

System.IO.FileLoadException

无法加载文件或程序集'System.Diagnostics.DiagnosticSource,版本= 4.0.0.0,区域性=中性,PublicKeyToken = cc7b13ffcd2ddd51'或其依赖项之一.找到的程序集的清单定义与程序集引用不匹配. (来自HRESULT的异常:0x80131040)

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

在System.Net.Http.WinHttpHandler.SendAsync(...)

at System.Net.Http.WinHttpHandler.SendAsync(...)

调查此问题后,我们发现导致上述失败的以下原因:

After investigating this issue we came to the following cause for the above failure:

  • System.Net.Http v 4.3.0 声明对 System.Diagnostics.DiagnosticSource v 4.3.0 的依赖或以上.从项目中引用System.Net.Http v 4.3.0时,将自动下载此软件包.
  • System.Net.Http v 4.3.0的NuGet软件包实际上包括System.Net.Http.dll v 4.1.1.0(截至2017年1月8日).
  • System.Diagnostics.DiagnosticSource v 4.3.0的NuGet软件包实际上包括System.Diagnostics.DiagnosticSource v 4.0.1.0(截至2017年1月8日).
  • System.Net.Http ver 4.1.1.0参考System.Diagnostics.DiagnosticSource v.4.0.0.0
  • System.Diagnostics.DiagnosticSource v.4.0.0.0与下载的dll v 4.0.1.0 v不完全匹配.
  • 当强命名库引用的版本不完全匹配时,.NET运行时仍会尝试查找引用的程序集.如果不能:库加载异常生成.另请参见以下备注
  • The package information page for System.Net.Http v 4.3.0 states dependency on System.Diagnostics.DiagnosticSource v 4.3.0 or above. This package is automatically downloaded when System.Net.Http v 4.3.0 is referenced from the project.
  • NuGet package of System.Net.Http v 4.3.0 in fact includes System.Net.Http.dll v 4.1.1.0 (as of Jan 8 2017).
  • NuGet package of System.Diagnostics.DiagnosticSource v 4.3.0 in fact includes System.Diagnostics.DiagnosticSource v 4.0.1.0 (as of Jan 8 2017).
  • System.Net.Http ver 4.1.1.0 references System.Diagnostics.DiagnosticSource v. 4.0.0.0
  • System.Diagnostics.DiagnosticSource v. 4.0.0.0 is not an exact match to v the downloaded dll v 4.0.1.0.
  • When the version of a strongly-named library reference is not in exact match, .NET run time still tries to find the referenced assembly. If it can't: the library load exception is generated. Also see the following remark

有几种解决方法:

  1. app.config选项:使用-引用应用程序.
  1. app.config option: Declare compatible versions (how far should we go with that?) with binding redirection in app.config for any "shared.dll" - referencing application.

<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
  <dependentAssembly>
    <assemblyIdentity name="System.Diagnostics.DiagnosticSource" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0" />
  </dependentAssembly>
</assemblyBinding>

  1. 将System.Diagnostics.DiagnosticSource.dll强制为版本4.0.0.0: 将对System.Diagnostics.DiagnosticSource v.4.0.0.0的NuGet引用添加到引用System.Net.Http的项目中,以阻止自动下载dll版本4.0.1.0.此选项失去了自动更新NuGet依赖项的能力,但使应用程序的部署少了配置.
  1. Force System.Diagnostics.DiagnosticSource.dll to version 4.0.0.0: Add NuGet reference to System.Diagnostics.DiagnosticSource v. 4.0.0.0 to the projects referencing System.Net.Http to preempt automatic download of dll version 4.0.1.0. This option looses ability to automatically update the NuGet dependency, but makes deployment of the applications configuration-less.

尽管适当的问题解决方案在于解决软件包所有者的上述NuGet软件包不一致问题,但让人感到a.如果将其固定在源代码中,则不需要使用System.Net.Http程序包使用代码的变通办法.

There is a nagging feeling though that the proper issue solution lies in fixing the aforementioned NuGet packages inconsistencies by the package's owners. When fixed at the source, no workaround for System.Net.Http package consuming code would be required.

问题:

  1. 为什么System.Net.Http v 4.3.0程序包包含不匹配的System.Net.Http.dll v 4.1.1,而早期版本的程序包4.1.1却不匹配?
  2. 我们应该继续执行上面提到的两种解决方法中的任何一种吗?
  3. 哪个更好?
  4. 或者:有其他解决方法吗?
  5. 或者:NuGet软件包是否即将更新,以解决不一致问题?

谢谢.

推荐答案

我认为回答我自己的问题在事实上是正确的,因为答案的99%已经存在.

I feel it would be factually correct to answer my own question because 99% of the the answer is already there.

github/corefx上的开发团队承认此问题解决方案将是一个方面另一个已知问题的作用是通过删除对System.Diagnostics的硬引用而解决的System.Net.Http项目中的.DiagnosticSource.dll.

The development team at github/corefx acknowledged this issue resolution would be a side effect of another known issue fix by the nature of removing the hard reference to System.Diagnostics.DiagnosticSource.dll from System.Net.Http project.

在此之前:根据个人喜好,可以使用提供的两种解决方法中的任何一种.

Until then: any of two provided workarounds is OK to use based on personal preferences.

这篇关于System.Net.Http NuGet包4.3.0参考在System.Diagnostics.DiagnosticSource ver 4.0.0.0参考上生成System.IO.FileLoadException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆