Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Unable to cast COM object of type System.__ComObject to class type mshtml.HTMLDocumentClass

859 views
Skip to first unread message

dedgod

unread,
Jan 10, 2007, 5:26:18 PM1/10/07
to

I posted this on the dotnet framework programming group, but this looks
like the better group to post this to..


This used to work on a machine with only .NET framework 1.1.
All the machines where it fails have framework 2.0 , though i have
machines where 2.0 redistributable is installed and it still works !@#

I am trying to read the results of a web page and display them in
Excel.

The following code
//before navigate event of the browser
private void axWebBrowser1_BeforeNavigate2(object sender,
AxSHDocVw.DWebBrowserEvents2_BeforeNavigate2Event e)
{
string cookie =
((mshtml.HTMLDocumentClass)((AxSHDocVw.AxWebBrowser)sender).Document).cooki­e;

}
results in the following exception

Exception: System.InvalidCastException
Message: Unable to cast COM object of type 'System.__ComObject' to
class type 'mshtml.HTMLDocumentClass'. COM components that enter the
CLR and do not support IProvideClassInfo or that do not have any
interop assembly registered will be wrapped in the __ComObject type.
Instances of this type cannot be cast to any other class; however they
can be cast to interfaces as long as the underlying COM component
supports QueryInterface calls for the IID of the interface.

What is happenning ? How can i fix this ?

Please help :(

Sheng Jiang[MVP]

unread,
Jan 14, 2007, 8:08:30 PM1/14/07
to
import mshtml.dll and use IHTMLDocument2,IHTMLDocument3.. etc instead of the
.net class

--
Regards
Sheng Jiang
Microsoft MVP in Visual C++
"dedgod" <nan...@gmail.com> wrote in message
news:1168467978.3...@i56g2000hsf.googlegroups.com...

I posted this on the dotnet framework programming group, but this looks
like the better group to post this to..


This used to work on a machine with only .NET framework 1.1.
All the machines where it fails have framework 2.0 , though i have
machines where 2.0 redistributable is installed and it still works !@#

I am trying to read the results of a web page and display them in
Excel.

The following code
//before navigate event of the browser
private void axWebBrowser1_BeforeNavigate2(object sender,
AxSHDocVw.DWebBrowserEvents2_BeforeNavigate2Event e)
{
string cookie =

((mshtml.HTMLDocumentClass)((AxSHDocVw.AxWebBrowser)sender).Document).cooki苟;

dedgod

unread,
Jan 22, 2007, 11:41:37 AM1/22/07
to
Thanks!
That fixed it..

In general, adapting my code to work in the .NET 2.0 Framework is
proving to be a lot of work..

Sheng Jiang[MVP] wrote:
> import mshtml.dll and use IHTMLDocument2,IHTMLDocument3.. etc instead of the
> .net class
>
> --
> Regards
> Sheng Jiang
> Microsoft MVP in Visual C++
> "dedgod" <nan...@gmail.com> wrote in message
> news:1168467978.3...@i56g2000hsf.googlegroups.com...
>
> I posted this on the dotnet framework programming group, but this looks
> like the better group to post this to..
>
>
> This used to work on a machine with only .NET framework 1.1.
> All the machines where it fails have framework 2.0 , though i have
> machines where 2.0 redistributable is installed and it still works !@#
>
> I am trying to read the results of a web page and display them in
> Excel.
>
> The following code
> //before navigate event of the browser
> private void axWebBrowser1_BeforeNavigate2(object sender,
> AxSHDocVw.DWebBrowserEvents2_BeforeNavigate2Event e)
> {
> string cookie =

> ((mshtml.HTMLDocumentClass)((AxSHDocVw.AxWebBrowser)sender).Document).cooki­e;

0 new messages