asp.net Web 应用程序中的程序集绑定问题,已启用融合日志

Assembly Binding Issue in asp.net web application, Enabled Fusion Log

我正在处理遗留 Web 应用程序,我遇到 运行 时间程序集绑定错误 (FileNotFoundException)

我查看了应用程序基目录,可以确认所需的版本正确的 DLL 和 public 令牌在 bin/ 目录下可用。

我在服务器上启用了 Fusion Log 以捕获详细信息,并意识到 CLR 首先在 GAC 中探测程序集(我认为这是为签名程序集设计的)下面是日志以供快速参考:

我可以通过在 GAC 中安装程序集使其工作 - 但问题和好奇心仍然存在,为什么在 GAC 中找不到它后 CLR 没有从应用程序基目录中选择它?

此外,从下面的日志中可以看出,在 GAC 之后,搜索是在目录 C:Windows/System32 与我的应用程序目录下执行的。我认为这是因为日志也说它在可执行文件 C:\Windows\system32\dllhost.exe

下是 运行

任何 help/comment 感谢!

*** Assembly Binder Log Entry  (6/28/2018 @ 4:18:02 AM) ***

The operation failed.
Bind result: hr = 0x80070002. The system cannot find the file specified.

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

=== Pre-bind state information ===
LOG: DisplayName = Microsoft.IdentityModel.Clients.ActiveDirectory, Version=3.19.3.10102, Culture=neutral, PublicKeyToken=31bf3856ad364e35
 (Fully-specified)
LOG: Appbase = file:///C:/Windows/system32/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = dllhost.exe
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: No application configuration file found.
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
LOG: GAC Lookup was unsuccessful.
LOG: Attempting download of new URL file:///C:/Windows/system32/Microsoft.IdentityModel.Clients.ActiveDirectory.DLL.
LOG: Attempting download of new URL file:///C:/Windows/system32/Microsoft.IdentityModel.Clients.ActiveDirectory/Microsoft.IdentityModel.Clients.ActiveDirectory.DLL.
LOG: Attempting download of new URL file:///C:/Windows/system32/Microsoft.IdentityModel.Clients.ActiveDirectory.EXE.
LOG: Attempting download of new URL file:///C:/Windows/system32/Microsoft.IdentityModel.Clients.ActiveDirectory/Microsoft.IdentityModel.Clients.ActiveDirectory.EXE.
LOG: All probing URLs attempted and failed.

*** Assembly Binder Log Entry  (6/28/2018 @ 4:18:02 AM) ***

The operation failed.
Bind result: hr = 0x80070002. The system cannot find the file specified.

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

=== Pre-bind state information ===
LOG: DisplayName = Microsoft.IdentityModel.Clients.ActiveDirectory, Version=3.19.3.10102, Culture=neutral, PublicKeyToken=31bf3856ad364e35
 (Fully-specified)
LOG: Appbase = file:///C:/Windows/system32/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = dllhost.exe
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: No application configuration file found.
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
LOG: GAC Lookup was unsuccessful.
LOG: Attempting download of new URL file:///C:/Windows/system32/Microsoft.IdentityModel.Clients.ActiveDirectory.DLL.
LOG: Attempting download of new URL file:///C:/Windows/system32/Microsoft.IdentityModel.Clients.ActiveDirectory/Microsoft.IdentityModel.Clients.ActiveDirectory.DLL.
LOG: Attempting download of new URL file:///C:/Windows/system32/Microsoft.IdentityModel.Clients.ActiveDirectory.EXE.
LOG: Attempting download of new URL file:///C:/Windows/system32/Microsoft.IdentityModel.Clients.ActiveDirectory/Microsoft.IdentityModel.Clients.ActiveDirectory.EXE.
LOG: All probing URLs attempted and failed.

*** Assembly Binder Log Entry  (6/28/2018 @ 4:18:03 AM) ***

The operation failed.
Bind result: hr = 0x80070002. The system cannot find the file specified.

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

=== Pre-bind state information ===
LOG: DisplayName = Microsoft.IdentityModel.Clients.ActiveDirectory, Version=3.19.3.10102, Culture=neutral, PublicKeyToken=31bf3856ad364e35
 (Fully-specified)
LOG: Appbase = file:///C:/Windows/system32/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = dllhost.exe
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: No application configuration file found.
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
LOG: The same bind was seen before, and was failed with hr = 0x80070002.
ERR: Unrecoverable error occurred during pre-download check (hr = 0x80070002).

*** Assembly Binder Log Entry  (6/28/2018 @ 4:18:03 AM) ***

The operation failed.
Bind result: hr = 0x80070002. The system cannot find the file specified.

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

=== Pre-bind state information ===
LOG: DisplayName = Microsoft.IdentityModel.Clients.ActiveDirectory, Version=3.19.3.10102, Culture=neutral, PublicKeyToken=31bf3856ad364e35
 (Fully-specified)
LOG: Appbase = file:///C:/Windows/system32/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = dllhost.exe
Calling assembly : MS.UST.EC.Oem.ServiceProxy, Version=1.0.0.0, Culture=neutral, PublicKeyToken=0753af11def5a5f8.
===
LOG: This bind starts in default load context.
LOG: No application configuration file found.
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
LOG: The same bind was seen before, and was failed with hr = 0x80070002.
ERR: Unrecoverable error occurred during pre-download check (hr = 0x80070002).

EXE 映像 C:\Windows\system32\dllhost.exe 被称为 "COM Surrogate" 主机。当你想激活一个 COM+ 组件服务,而不是在你自己的进程中加载​​它时(为了安全或稳定),将调用 dllhost.exe 来加载组件并将其公开为 "out of process" 激活,然后通过一些透明的代理通道与您的进程通信,允许调用程序假装组件是在本地加载的。

这意味着您可能有一些代码正在通过 COM+ 接口访问并在进程外启动。此代码依次尝试加载 Microsoft.IdentityModel.Clients.ActiveDirectory 程序集。问题是,它不再在您的进程中,并且不会参与您设置的任何绑定策略(私有 bin 路径、绑定重定向等)。这就是为什么您看到它首先尝试 GAC 然后找不到您的 dll 的原因 - 这不是您的进程。

寻找您可能正在加载的任何组件,它是一个 COM 组件:您是否正在使用某些 COM TypeLib 或某个 COM dll 的运行时可调用包装器,或者您是否有任何继承 System.EnterpriseServices.ServicedComponent 的代码?

如果您能找到启动进程外 COM 组件的位置,您也许可以重构它以将逻辑引入进程内并以这种方式解决加载问题。否则,您必须将程序集放入 GAC。