首页 > 解决方案 > asp.net web 应用程序中的程序集绑定问题,启用融合日志

问题描述

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

我查看了应用程序基目录,可以确认 bin/ 目录下提供了具有正确版本和公共令牌的所需 DLL。

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

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

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

任何帮助/评论表示赞赏!

*** 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).

标签: c#asp.netdebuggingclrgac

解决方案


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

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

查找您可能正在加载的任何 COM 组件:您是在使用一些 COM TypeLib,还是对一些 COM dll 使用 Runtime Callable Wrapper,或者您是否有任何继承的代码System.EnterpriseServices.ServicedComponent

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


推荐阅读