How do I make mshtml load CustomMarshalers?

716 views Asked by At

I'm working on a legacy c# application that uses .Net framework 4. The app uses the WebBrowser control and references "Microsoft HTML Object Library" (mshtml). The current version is deployed to Server 2003 and will only run if .Net framework 2 SDK is installed.

The push is to deploy the app to server 2008 but without the framework SDK. But of course, the app won't run. The error generated is "Unable to cast COM object of type 'System.__ComObject' to class type 'mshtml.HTMLFormElementClass'." I realize that this particular error could be resolved by casting to an interface. In fact, I made this change and the app ran until the next mshtml casting error. There are over 200 lines of similar code spread throughout the application and no good way to test changes made.

I've used Fusion Log Viewer to get a sense of what dependencies are being loaded and have found that CustomMarshalers is being loaded by mshtml when then app is started from Visual Studio 2010 or if, as sys admin discovered, Visual Studio 2010 is installed on server 2008 prior to launching the app. My gut feeling is that I need mshtml to load CustomMarshalers regardless of the presence of Visual Studio.

What is it about Visual Studio that causes mshtml to load CustomMarshalers? How can I make this happen from code?

Fusion Log Viewer entry for CustomMarshalers:

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

There are 0 answers