微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

绑定重定向失败 Fusion日志中什么代表“从源运行”阶段?

如何解决绑定重定向失败 Fusion日志中什么代表“从源运行”阶段?

我遇到了我无法理解的程序集绑定重定向失败的问题。

我以以下方式为测试项目定义了绑定重定向

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Castle.Core" publicKeyToken="407dd0808d44fbdc" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.4.1.0" newVersion="4.4.1.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

该项目使用SDK格式<Project Sdk="Microsoft.NET.Sdk">,并在VS2019 v16.7.2中构建。

使用内置测试运行程序执行测试时,会引发以下运行时异常:

OneTimeSetUp: System.IO.FileLoadException : Could not load file or assembly 'Castle.Core,Version=4.4.1.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)
      ----> System.IO.FileLoadException : Could not load file or assembly 'Castle.Core,Version=4.0.0.0,PublicKeyToken=407dd0808d44fbdc' or one of its dependencies. The located assembly's manifest deFinition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

我已启用Fusion Logs以查看运行程序未能加载程序集的原因:

*** Assembly Binder Log Entry  (02-Oct-20 @ 16:39:34) ***

The operation Failed.
Bind result: hr = 0x80131040. No description available.

Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dll
Running under executable  C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\IDE\Extensions\TestPlatform\testhost.exe
--- A detailed error log follows. 

=== Pre-bind state information ===
LOG: displayName = Castle.Core,PublicKeyToken=407dd0808d44fbdc
 (Fully-specified)
LOG: Appbase = file:///C:/Users/_.__/src/_/Artifacts/IntegrationTests/x64/Debug/net472/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = Tests_373511859
Calling assembly : Castle.Windsor,Version=5.0.0.0,PublicKeyToken=407dd0808d44fbdc.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Users\_.__\src\_\Artifacts\IntegrationTests\x64\Debug\net472\_IntegrationTest.dll.config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
LOG: Redirect found in application configuration file: 4.0.0.0 redirected to 4.4.1.0.
LOG: Post-policy reference: Castle.Core,PublicKeyToken=407dd0808d44fbdc
LOG: GAC Lookup was unsuccessful.
LOG: Attempting download of new URL file:///C:/Users/_.__/src/_/Artifacts/IntegrationTests/x64/Debug/net472/Castle.Core.DLL.
LOG: Assembly download was successful. Attempting setup of file: C:\Users\_.__\src\_\Artifacts\IntegrationTests\x64\Debug\net472\Castle.Core.dll
LOG: Entering run-from-source setup phase.
LOG: Assembly Name is: Castle.Core,PublicKeyToken=407dd0808d44fbdc
WRN: Comparing the assembly name resulted in the mismatch: Minor 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.

我已对其进行了仔细检查,文件“ .. \ Artifacts \ IntegrationTests \ x64 \ Debug \ net472 \ Castle.Core.dll”的版本为预期的4.4.1.0,但由于未知原因,日志说它是4.0 .0.0

我注意到在“从源运行”阶段中探测失败。这是否意味着程序集是从日志中提到的其他位置加载的?

据我所知,这种行为似乎是绑定机制中的错误

我期待一些提示,这些提示将帮助我找出问题的根本原因。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。