如何使mshtml加载CustomMarshalers?

时间:2014-12-01 23:51:04

标签: c# .net-assembly assemblybinding

我正在处理使用.Net framework 4的传统c#应用程序。该应用程序使用WebBrowser控件和引用" Microsoft HTML Object Library" (MSHTML)。当前版本部署到Server 2003,只有在安装.Net framework 2 SDK时才会运行。

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

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

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

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.

0 个答案:

没有答案