0

我正在开发一个使用 .Net 框架 4 的旧版 c# 应用程序。该应用程序使用 WebBrowser 控件并引用“Microsoft HTML 对象库”(mshtml)。当前版本已部署到 Server 2003,并且仅在安装了 .Net framework 2 SDK 时才会运行。

推送是将应用程序部署到服务器 2008 但没有框架 SDK。但当然,该应用程序不会运行。生成的错误是“无法将‘System.__ComObject’类型的 COM 对象转换为类类型‘mshtml.HTMLFormElementClass’。” 我意识到这个特定的错误可以通过转换为接口来解决。事实上,我做了这个改变,应用程序一直运行到下一个 mshtml 转换错误。有超过 200 行类似的代码分布在整个应用程序中,并且没有很好的方法来测试所做的更改。

我使用 Fusion Log Viewer 来了解正在加载哪些依赖项,并发现当从 Visual Studio 2010 启动应用程序时,mshtml 正在加载 CustomMarshalers,或者如果系统管理员发现 Visual Studio 2010 安装在服务器 2008 在启动应用程序之前。我的直觉是,无论是否存在 Visual Studio,我都需要 mshtml 来加载 CustomMarshalers。

导致 mshtml 加载 CustomMarshalers 的 Visual Studio 是什么?我怎样才能从代码中实现这一点?

CustomMarshalers 的 Fusion Log Viewer 条目:

*** Assembly Binder Log Entry  (11/24/2014 @ 1:42:11 PM) ***

The operation was successful.
Bind result: hr = 0x0. The operation completed successfully.

Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
Running under executable  C:\Users\[user]\Documents\[app]\Code\[app]\bin\Debug\[app].exe
--- A detailed error log follows. 

=== Pre-bind state information ===
LOG: User = [domain]\[user]
LOG: DisplayName = CustomMarshalers, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
 (Fully-specified)
LOG: Appbase = file:///C:/Users/[user]/Documents/[app]/Code/[app]/bin/Debug/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = [app].exe
Calling assembly : Microsoft.mshtml, Version=7.0.3300.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Users\[user]\Documents\[app]\Code\[app]\bin\Debug\[app].exe.Config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy reference: CustomMarshalers, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
LOG: Found assembly by looking in the GAC.
LOG: Binding succeeds. Returns assembly from C:\Windows\Microsoft.Net\assembly\GAC_32\CustomMarshalers\v4.0_4.0.0.0__b03f5f7f11d50a3a\CustomMarshalers.dll.
LOG: Assembly is loaded in default load context.


*** Assembly Binder Log Entry  (11/24/2014 @ 1:42:11 PM) ***

The operation was successful.
Bind result: hr = 0x0. The operation completed successfully.

Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
Running under executable  C:\Users\[user]\Documents\[app]\Code\[app]\bin\Debug\[app].exe
--- A detailed error log follows. 

=== Pre-bind state information ===
LOG: User = [domain]\[user]
LOG: DisplayName = CustomMarshalers, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
 (Fully-specified)
LOG: Appbase = file:///C:/Users/[user]/Documents/[app]/Code/[app]/bin/Debug/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = [app].exe
Calling assembly : Microsoft.mshtml, Version=7.0.3300.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Users\[user]\Documents\[app]\Code\[app]\bin\Debug\[app].exe.Config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy reference: CustomMarshalers, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
LOG: Found assembly by looking in the GAC.
LOG: Binding succeeds. Returns assembly from C:\Windows\Microsoft.Net\assembly\GAC_32\CustomMarshalers\v4.0_4.0.0.0__b03f5f7f11d50a3a\CustomMarshalers.dll.
LOG: Assembly is loaded in default load context.
4

0 回答 0