Discussion:
Unable to cast COM object of type 'System.__ComObject' to class type 'mshtml.HTMLDocumentClass'
(too old to reply)
Nandan Dharwadker
2007-01-10 21:44:27 UTC
Permalink
Hi,

I am trying to read the results of a web page and display them in a web
browser control.
I am using .NET framework 1.1, though the clients machine has framework
2.0 as well.


The following code
//before navigate event of the browser
private void axWebBrowser1_BeforeNavigate2(object sender,
AxSHDocVw.DWebBrowserEvents2_BeforeNavigate2Event e)
{
<snip>

string cookie =
((mshtml.HTMLDocumentClass)((AxSHDocVw.AxWebBrowser)sender).Document).cookie;

}

results in the following exception ONLY ON SOME MACHINES

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.


But this does not happen on any of my test machines. even if i install
the 2.0 framework.

I load the microsoft.mshtml.dll from the same directory as the
application.
I split up and logged errors and detected that if i do the following
individually

AxSHDocVw.AxWebBrowser browser = new AxSHDocVw.AxWebBrowser();
object myname = ((AxSHDocVw.AxWebBrowser)sender).Name; // displays
AxSHDocVw.AxWebBrowser
object mydocument = ((AxSHDocVw.AxWebBrowser)sender).Document;
mshtml.HTMLDocumentClass mydocclass = new HTMLDocumentClass();
object myhtmldocclass = ((mshtml.HTMLDocumentClass)(mydocument));

its this last line that causes the exception.

What is happenning ?

Please help me :-(
Nandan Dharwadker
2007-01-22 16:43:13 UTC
Permalink
To help anyone else who has a similar problem

"import mshtml.dll and use IHTMLDocument2,IHTMLDocument3.. etc instead
of the
.net class

--
Regards
Sheng Jiang
Microsoft MVP in Visual C++


"
This worked for me...
Post by Nandan Dharwadker
Hi,
I am trying to read the results of a web page and display them in a web
browser control.
I am using .NET framework 1.1, though the clients machine has framework
2.0 as well.
The following code
//before navigate event of the browser
private void axWebBrowser1_BeforeNavigate2(object sender,
AxSHDocVw.DWebBrowserEvents2_BeforeNavigate2Event e)
{
<snip>
string cookie =
((mshtml.HTMLDocumentClass)((AxSHDocVw.AxWebBrowser)sender).Document).cookie;
}
results in the following exception ONLY ON SOME MACHINES
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.
But this does not happen on any of my test machines. even if i install
the 2.0 framework.
I load the microsoft.mshtml.dll from the same directory as the
application.
I split up and logged errors and detected that if i do the following
individually
AxSHDocVw.AxWebBrowser browser = new AxSHDocVw.AxWebBrowser();
object myname = ((AxSHDocVw.AxWebBrowser)sender).Name; // displays
AxSHDocVw.AxWebBrowser
object mydocument = ((AxSHDocVw.AxWebBrowser)sender).Document;
mshtml.HTMLDocumentClass mydocclass = new HTMLDocumentClass();
object myhtmldocclass = ((mshtml.HTMLDocumentClass)(mydocument));
its this last line that causes the exception.
What is happenning ?
Please help me :-(
Bhavin Chheda
2008-10-14 21:13:21 UTC
Permalink
Hello,
Below is my existing code...
mshtml.IHTMLDocument3 doc = (mshtml.IHTMLDocument3)axWebBrowser1.Document;
string strHtml = ((mshtml.HTMLDocumentClass) (doc)).documentElement.outerHTML +
Environment.NewLine;

But I am getting error as......
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.

Please Help,
***@gmail.com


From http://www.developmentnow.com/g/21_2007_1_0_0_913194/Unable-to-cast-COM-object-of-type-System--ComObject-to-class-type-mshtml-HTMLDocumentClass.ht

Posted via DevelopmentNow.com Group
http://www.developmentnow.com/g/
xirurg
2008-12-17 21:01:00 UTC
Permalink
run
C:\Program Files\Common files\Merge Modules\vs_piaredist.exe

I had similar issue and it helped
Post by Bhavin Chheda
Hello,
Below is my existing code...
mshtml.IHTMLDocument3 doc = (mshtml.IHTMLDocument3)axWebBrowser1.Document;
string strHtml = ((mshtml.HTMLDocumentClass) (doc)).documentElement.outerHTML +
Environment.NewLine;
But I am getting error as......
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.
Please Help,
From http://www.developmentnow.com/g/21_2007_1_0_0_913194/Unable-to-cast-COM-object-of-type-System--ComObject-to-class-type-mshtml-HTMLDocumentClass.htm
Posted via DevelopmentNow.com Groups
http://www.developmentnow.com/g/
Loading...