Microsoft KB Archive/305622

= Primary interop assembly for MSHTML increases size of redistributable file =

Article ID: 305622

Article Last Modified on 5/12/2007

-

APPLIES TO


 * Microsoft Visual Studio .NET 2002 Professional Edition
 * Microsoft Visual Studio .NET 2002 Enterprise Architect
 * Microsoft Visual Studio .NET 2002 Enterprise Developer
 * Microsoft Visual Studio .NET 2002 Academic Edition

-



This article was previously published under Q305622



SYMPTOMS
When you use the Microsoft Internet Explorer MSHTML.dll file in a Visual Studio .NET application, you may notice that the Primary Interop Assembly (PIA) for MSHTML is greater than 7.5 megabytes (MB). This is three times greater than the size of MSHTML itself. The size of this assembly is particularly problematic if you want to distribute your application over the Web.



CAUSE
If you use the Ildasm.exe command from the Visual Studio .NET command prompt to open the Interop assembly, you can see that the process to generate the Interop DLL creates objects and interfaces for all of the corresponding items in the MSHTML.dll file. Additionally, the process to generate the Interop DLL creates a delegate for every event on every object in the Document Object Model (DOM). This necessitates a large assembly.



RESOLUTION
The best alternative is to call only MSHTML through late binding, which does not require the distribution of an MSHTML Interop assembly.

To do this, use the classes in the System.Runtime.InteropServices namespace to call the IDispatch interface against the Internet Explorer DOM. The following code demonstrates how to do this:

Microsoft Visual Basic .NET code Imports System.Runtime.InteropServices Imports System.Reflection

Private Sub AxWebBrowser1_DocumentComplete(ByVal sender As Object, _   ByVal e As AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEvent) _ Handles AxWebBrowser1.DocumentComplete Dim htm As Object Dim typ As Type Dim docTitle As String

typ = Type.GetTypeFromCLSID(New System.Guid(&quot;{3050F4E7-98B5-11CF-BB82-00AA00BDCE0B}&quot;)) htm = AxWebBrowser1.Document docTitle = typ.InvokeMember(&quot;title&quot;, BindingFlags.GetProperty, Nothing, htm, Nothing) MessageBox.Show(&quot;Title is &quot; & docTitle) End Sub Microsoft Visual C# .NET code using System.Runtime.InteropServices; using System.Reflection; private void DocumentComplete(object sender, AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEvent e)   { object htm; Type typ; string docTitle;

typ = Type.GetTypeFromCLSID(new System.Guid(&quot;{3050F4E7-98B5-11CF-BB82-00AA00BDCE0B}&quot;)); htm = axWebBrowser1.Document; docTitle = typ.InvokeMember(&quot;title&quot;, BindingFlags.GetProperty, null, htm, null).ToString; MessageBox.Show(&quot;Title is &quot; + docTitle); }



STATUS
This behavior is by design.



Steps to reproduce the problem

 * 1) In your Visual Studio .NET project, click Project, and then click Add Reference.
 * 2) On the COM tab, click Microsoft HTML Object Library to add the PIA.

