简体   繁体   English

为什么 Autofac.Integration.WebApi.Owin 5.0.0 在 TargetFramework v4.7.1 上引用 System.Net.Http 4.2.0?

[英]Why is Autofac.Integration.WebApi.Owin 5.0.0 referencing System.Net.Http 4.2.0 on TargetFramework v4.7.1?

I have an assembly with TargetFrameworkVersion v4.7.1 that has a reference to Autofac.Integration.WebApi.Owin 5.0.0.我有一个带有 TargetFrameworkVersion v4.7.1 的程序集,它引用了 Autofac.Integration.WebApi.Owin 5.0.0。

During compile, I get a warning saying warning MSB3277: Found conflicts between different versions of "System.Net.Http" that could not be resolved. These reference conflicts are listed in the build log when log verbosity is set to detailed.在编译过程中,我收到一条警告,说warning MSB3277: Found conflicts between different versions of "System.Net.Http" that could not be resolved. These reference conflicts are listed in the build log when log verbosity is set to detailed. warning MSB3277: Found conflicts between different versions of "System.Net.Http" that could not be resolved. These reference conflicts are listed in the build log when log verbosity is set to detailed. Running my application on a server that has only .NET Framework 4.7.1 installed, I get the following runtime exception在仅安装了 .NET Framework 4.7.1 的服务器上运行我的应用程序,我收到以下运行时异常

System.IO.FileNotFoundException: Could not load file or assembly 'System.Net.Http, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
File name: 'System.Net.Http, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
   at Owin.AutofacWebApiAppBuilderExtensions.UseAutofacWebApi(IAppBuilder app, HttpConfiguration configuration)

Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dll
Running under executable  C:\xx\yyServer\yyServer.exe
--- A detailed error log follows. 

=== Pre-bind state information ===
LOG: DisplayName = System.Net.Http, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
 (Fully-specified)
LOG: Appbase = file:///C:/xx/yy/Server/
LOG: Initial PrivatePath = NULL
Calling assembly : Autofac.Integration.WebApi.Owin, Version=5.0.0.0, Culture=neutral, PublicKeyToken=17863af14b0044da.

From dotPeek, I can see the following information about the assemblies从 dotPeek,我可以看到有关程序集的以下信息

Autofac.Integration.WebApi, 5.0.0.0, msil, .Net Framework v4.6.1, Debug
   References:
     - System.Net.Http (4.2.0.0)
Autofac.Integration.WebApi.Owin, 5.0.0.0, msil, .Net Framework v4.6.1, Debug
   References:
     - System.Net.Http (4.2.0.0)
My.Assembly, 1.0.0.0, msil, .Net Framework v4.7.1, Debug
   References:
     - System.Net.Http (4.0.0.0)

If I create a new and empty project targeting .NET Framework v.4.6.1-4.7.1, the System.Net.Http reference claims Version is 4.0.0.0.如果我创建一个面向 .NET Framework v.4.6.1-4.7.1 的新的空项目,System.Net.Http 引用声称版本为 4.0.0.0。 If I bump the project up to 4.7.1, the System.Net.Http reference says 4.2.0.0.如果我将项目提升到 4.7.1,System.Net.Http 引用会显示 4.2.0.0。 Looking at nuget packages for System.Net.Http, there is no version 4.2.0.查看 System.Net.Http 的 nuget 包,没有 4.2.0 版本。 Using .NET Framework 4.7.2 for the actual project might work, but I'm not in a position to update to a new TargetFramework at the moment.在实际项目中使用 .NET Framework 4.7.2 可能会起作用,但我目前无法更新到新的 TargetFramework。

Adding the following assembly redirect to the app.config appears to fix this particular issue at runtime, however I'm not sure how happy I am with redirecting framework assemblies, and what other consequences that might bring.将以下程序集重定向添加到 app.config 似乎可以在运行时解决这个特定问题,但是我不确定我对重定向框架程序集有多满意,以及可能带来的其他后果。 The compile time warning is still present.编译时警告仍然存在。

<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>

Why is the Autofac assembiles referencing version 4.2.0?为什么 Autofac 程序集引用版本 4.2.0? Is there an issue with the package?包裹有问题吗? Are there better ways to fix this rather than using an assembly redirect?有没有比使用程序集重定向更好的方法来解决这个问题?

Taking Autofac out of it for a minute, if you do a search on system.net.http 4.2.0.0 you'll find that this is a problem with a lot of packages, from DocumentDb to System.Collections.Immutable .稍等片刻,如果您system.net.http 4.2.0.0上搜索system.net.http 4.2.0.0您会发现这是很多包的问题,​​从DocumentDbSystem.Collections.Immutable It apparently stems from a tooling issue where an assembly was built using VS 2017 (which is where System.Net.Http 4.2.0.0 comes from) and at build time that version was there, yet at runtime the project was not built with the same toolset and the assembly goes missing.它显然源于一个工具问题,其中使用 VS 2017 构建程序集(这是 System.Net.Http 4.2.0.0 的来源)并且在构建时该版本在那里,但在运行时该项目不是用相同的工具集和程序集丢失。

As you found, the short-term workaround is the assembly binding redirect.如您所见,短期解决方法是程序集绑定重定向。

For the longer term workaround, the Autofac package needs an update.对于长期解决方法,Autofac 包需要更新。 I've filed an issue on your behalf.我已经代表你提交了一个问题。

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

相关问题 为什么添加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? Microsoft WebAPI要求提供System.Net.Http版本= 4.0.0.0 - Microsoft WebAPI asks for System.Net.Http, Version=4.0.0.0 为什么我不能在System.Net.Http引用的解决方案中使用System.Net.Http包? - Why I can not use System.Net.Http package in a solution with System.Net.Http reference? Unity Api 兼容级别为 .NET Standard 2 但 Visual Studio 继续使用 .NET v4.7.1 - Unity Api Compability Level is .NET Standard 2 but Visual Studio keeps using .NET v4.7.1 为什么System.Net.Http HttpClient编码我的请求URL? - Why is System.Net.Http HttpClient encoding my request URL? 分发System.Net.Http - Distributing System.Net.Http System.Net.Http 的绑定重定向不起作用 - 为什么? - Binding redirect for System.Net.Http doesn't work - why? WebAPI + OWIN + SignalR + Autofac - WebAPI + OWIN + SignalR + Autofac 查看将在 HttpResponseMessage / HttpRequestMessage (System.Net.Http, WebAPI) 中发送/接收的原始标头 - View Raw Headers that will be sent/received in HttpResponseMessage / HttpRequestMessage (System.Net.Http, WebAPI) 找不到框架“.NETFramework,Version=v4.7.1”的参考程序集 - Reference assemblies for framework ".NETFramework,Version=v4.7.1" were not found
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM