Nandan Dharwadker
2007-01-10 21:44:27 UTC
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 :-(
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 :-(