2

In C# I have Object htmlDoc = _webbrowser.Document; and when I step through the code in debug mode, I have htmlDoc = {mshtml.HTMLDocumentClass} showing when I mouse over the Object htmlDoc assignment.

But when I type this code in the IDE, HTMLDocument htmlDoc = new HTMLDocumentClass();, Visual Studio does not recognize HTMLDocument, nor does it recognize the HTMLDocumentClass class.

I have included the namespace of System.Windows.Forms and I give reference to the DLL of the same name and it is version 4.0.0.0 and runtime version v4.0.30319. I tried to add the namespace System.Windows.Brower but the IDE did not recognize its existence. Why does the debugger seem to recognize the mshtml.HTMLDocumentClass but the code itself does not recognize it?

Jacob
  • 77,566
  • 24
  • 149
  • 228
xarzu
  • 8,657
  • 40
  • 108
  • 160

1 Answers1

3

The .NET HtmlDocument class:

...is based on the unmanaged interfaces implemented by Internet Explorer's DHTML DOM: IHTMLDocument, IHTMLDocument2, IHTMLDocument3, and IHTMLDocument4. Only the most frequently used properties and methods on these unmanaged interfaces are exposed by HtmlDocument. You can access all other properties and methods directly using the DomDocument property, which you can cast to the desired unmanaged interface pointer.

The mshtml.HTMLDocumentClass instance you're seeing comes via the interop library for the COM component internally referenced by .NET libraries; it's not publicly exposed. Unless you add a reference to this in your project and are using the namespace, HTMLDocumentClass does not exist (directly) in your project. I believe the DLL you'd have to add to access this directly is named Microsoft.mshtml.dll.

Jacob
  • 77,566
  • 24
  • 149
  • 228