在GAC中找不到程序集时,.NET从何处获取该程序集



我正在运行

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

我找到了程序集绑定日志查看器(Fusilogvw.exe(,我很难理解从中得到的日志。

*** Assembly Binder Log Entry  (10/26/2022 @ 7:23:21 PM) ***
The operation failed.
Bind result: hr = 0x80131040. No description available.
Assembly manager loaded from:  C:WindowsMicrosoft.NETFramework64v4.0.30319clr.dll
Running under executable  C:Program FilesMicrosoft Visual Studio2022ProfessionalCommon7IDEExtensionsTestPlatformtesthost.net472.exe
--- A detailed error log follows. 
=== Pre-bind state information ===
LOG: DisplayName = Castle.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc
(Fully-specified)
LOG: Appbase = file:///C:/git/company/Tests/WebDriver/regression.TestSuite/bin/Debug/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = Tests_812982921
Calling assembly : CompanyLib, Version=4.4.0.29278, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:gitcompanyTestsWebDriverregression.TestSuitebinDebugregression.TestSuite.dll.config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:WindowsMicrosoft.NETFramework64v4.0.30319configmachine.config.
LOG: Post-policy reference: Castle.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc
LOG: GAC Lookup was unsuccessful.
LOG: Attempting download of new URL file:///C:/git/company/Tests/WebDriver/regression.TestSuite/bin/Debug/Castle.Core.DLL.
LOG: Assembly download was successful. Attempting setup of file: C:gitcompanyTestsWebDriverregression.TestSuitebinDebugCastle.Core.dll
LOG: Entering run-from-source setup phase.
LOG: Assembly Name is: Castle.Core, Version=5.0.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc
WRN: Comparing the assembly name resulted in the mismatch: Major Version
ERR: The assembly reference did not match the assembly definition found.
ERR: Run-from-source setup phase failed with hr = 0x80131040.
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.
*** Assembly Binder Log Entry  (10/26/2022 @ 7:23:21 PM) ***
The operation failed.
Bind result: hr = 0x80131040. No description available.
Assembly manager loaded from:  C:WindowsMicrosoft.NETFramework64v4.0.30319clr.dll
Running under executable  C:Program FilesMicrosoft Visual Studio2022ProfessionalCommon7IDEExtensionsTestPlatformtesthost.net472.exe
--- A detailed error log follows. 
=== Pre-bind state information ===
LOG: DisplayName = Castle.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc
(Fully-specified)
LOG: Appbase = file:///C:/git/company/Tests/WebDriver/regression.TestSuite/bin/Debug/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = Tests_812982921
Calling assembly : CompanyLib, Version=4.4.0.29278, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:gitcompanyTestsWebDriverregression.TestSuitebinDebugregression.TestSuite.dll.config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:WindowsMicrosoft.NETFramework64v4.0.30319configmachine.config.
LOG: Post-policy reference: Castle.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc
LOG: GAC Lookup was unsuccessful.
LOG: Attempting download of new URL file:///C:/git/company/Tests/WebDriver/regression.TestSuite/bin/Debug/Castle.Core.DLL.
LOG: Assembly download was successful. Attempting setup of file: C:gitcompanyTestsWebDriverregression.TestSuitebinDebugCastle.Core.dll
LOG: Entering run-from-source setup phase.
LOG: Assembly Name is: Castle.Core, Version=5.0.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc
WRN: Comparing the assembly name resulted in the mismatch: Major Version
ERR: The assembly reference did not match the assembly definition found.
ERR: Run-from-source setup phase failed with hr = 0x80131040.
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.

如果有人能向我介绍文档或从高层解释本日志中的以下概念,我将不胜感激;"预绑定","调用程序集">

特别是我的问题是

LOG: GAC Lookup was unsuccessful.
LOG: Attempting download of new URL file:///C:/git/company/Tests/WebDriver/regression.TestSuite/bin/Debug/Castle.Core.DLL.

由于程序集不在GAC中,.NET在哪里查找从何处下载程序集?我在regression.TestSuite.csprojapp.config中没有看到任何对此程序集的引用——在app.config中只有一个带有bindingRedirect`的dependentAssembly元素。

我已尝试更新bindingRedirect以针对较新版本5.0.0.0,但仍遇到此问题。

好的,我已经解决了我的具体问题,并有了我的问题的答案,我将在这里为其他.NET程序集绑定新手发布。

我现在理解的"预绑定"是在运行时尝试定位程序集之前我们对程序集的了解。

"calling assembly"是由调用代码调用的程序集,而调用代码又要求提取该程序集。即:项目A直接依赖于项目B,而项目B依赖于项目C。当A调用B中的代码时,运行时必须提取C。在本例中,B是调用程序集。

至于.NET下载的文件在GAC中找不到,答案是微妙的,这取决于您的设置,但我在这里找到了所有好的细节。

真正让我点击的是阅读了关于运行时如何定位程序集的完整文档。读完这篇文章后,我无法理解即使在更新bindingRedirect以指向5.0.0.0(这是应用程序库"binpath"中程序集的版本(之后,FusionLog仍然显示4.0.0.0的"Post Policy"版本。

这让我看到了<assemblyBinding>的子元素。在那里我找到了答案。。。

为每个程序集使用一个dependentAssembly元素。

所以我有两个问题。

  1. 我在单个dependentAssembly元素中放置了多个程序集重定向(MS在这方面没有出错,它只是默默地忽略第一个下的任何其他程序集重定向(
  2. CCD_ 11没有针对正确的新版本

Borked app.config

<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.ValueTuple" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Threading.Tasks.Extensions" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.2.0.1" newVersion="4.2.0.1" />
<assemblyIdentity name="Castle.Core" publicKeyToken="407dd0808d44fbdc" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="5.0.0.0" />
</dependentAssembly>
</assemblyBinding>

修复了app.config

<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.ValueTuple" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Threading.Tasks.Extensions" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.2.0.1" newVersion="4.2.0.1" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Castle.Core" publicKeyToken="407dd0808d44fbdc" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="5.0.0.0" />
</dependentAssembly>
</assemblyBinding>

最新更新