根据 NuGet 的说法,我正在处理的项目安装了 System.Net.Http 版本 4.3.3。它在 Web.config 文件中有一个绑定重定向,可以将其重定向到 4.2.0.0 版,这出于某种原因起作用:
<dependentAssembly>
<assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.2.0.0" newVersion="4.2.0.0" />
</dependentAssembly>
Run Code Online (Sandbox Code Playgroud)
我将其更改为指向 4.3.3.0,这是 NuGet 所说的已安装版本:
<dependentAssembly>
<assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.3.3.0" newVersion="4.3.3.0" />
</dependentAssembly>
Run Code Online (Sandbox Code Playgroud)
...但现在当我尝试调试 ASP.NET 站点时出现此错误:
Could not load file or assembly 'System.Net.Http' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
=== Pre-bind state information ===
LOG: DisplayName = System.Net.Http
(Partial)
WRN: Partial binding information was supplied for an assembly:
WRN: Assembly Name: System.Net.Http | Domain ID: 2
WRN: A partial bind occurs when only part of the assembly display name is provided.
WRN: This might result in the binder loading an incorrect assembly.
WRN: It is recommended to provide a fully specified textual identity for the assembly,
WRN: that consists of the simple name, version, culture, and public key token.
WRN: See whitepaper http://go.microsoft.com/fwlink/?LinkId=109270 for more information and common solutions to this issue.
LOG: Appbase = file:///C:/.../Dev/Src/Web/PortalSite/
LOG: Initial PrivatePath = C:\...\Dev\Src\Web\PortalSite\bin
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\...\Dev\Src\Web\PortalSite\web.config
LOG: Using host configuration file: C:\...\Documents\IISExpress\config\aspnet.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/.../AppData/Local/Temp/Temporary ASP.NET Files/vs/e31848dc/3694ba06/System.Net.Http.DLL.
LOG: Attempting download of new URL file:///C:/.../AppData/Local/Temp/Temporary ASP.NET Files/vs/e31848dc/3694ba06/System.Net.Http/System.Net.Http.DLL.
LOG: Attempting download of new URL file:///C:/.../Dev/Src/Web/PortalSite/bin/System.Net.Http.DLL.
LOG: Using application configuration file: C:\...\Dev\Src\Web\PortalSite\web.config
LOG: Using host configuration file: C:\...\Documents\IISExpress\config\aspnet.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Redirect found in application configuration file: 4.2.0.0 redirected to 4.3.3.0.
LOG: Post-policy reference: System.Net.Http, Version=4.3.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
LOG: Attempting download of new URL file:///C:/.../AppData/Local/Temp/Temporary ASP.NET Files/vs/e31848dc/3694ba06/System.Net.Http.DLL.
LOG: Attempting download of new URL file:///C:/.../AppData/Local/Temp/Temporary ASP.NET Files/vs/e31848dc/3694ba06/System.Net.Http/System.Net.Http.DLL.
LOG: Attempting download of new URL file:///C:/.../Dev/Src/Web/PortalSite/bin/System.Net.Http.DLL.
WRN: Comparing the assembly name resulted in the mismatch: Minor Version
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.
Run Code Online (Sandbox Code Playgroud)
更令人困惑的是,bin该站点目录中的 DLL 版本似乎再次不同:
PS C:\...\Dev\Src\Web\PortalSite\bin> (Get-Item ...\bin\Debug\System.Net.Http.dll).VersionInfo
ProductVersion FileVersion FileName
-------------- ----------- --------
4.6.25908.02 ... 4.6.25908.02 C:\...\Dev\Src\Web\PortalSite\bin\System.Net.Http.dll
Run Code Online (Sandbox Code Playgroud)
这是怎么回事?重定向以前是如何工作的,为什么现在不起作用?
Mah*_*hdi 15
不要使用任何bindingRedirect for System.Net.Http,从配置文件中删除,并且不要认为女巫版本正在使用,这是由您的系统管理的
我发现将它添加到配置文件会导致严重的问题,因为每个文件使用该 dll 的不同版本。
从配置中删除System.Net.Http解决了我导致错误和找不到程序集的疯狂问题。
原来我bin目录中的DLL版本实际上是 version 4.2.0.0,它显然是与Visual Studio 2017捆绑在一起的,而NuGet包版本中分发的版本4.3.3是 DLL version 4.1.1.2,它根本没有被使用。令人困惑!但这解释了为什么重定向到 DLL 版本4.2.0.0有效而重定向到4.3.0.0没有。
| 归档时间: |
|
| 查看次数: |
9036 次 |
| 最近记录: |