By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,279 Members | 2,107 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,279 IT Pros & Developers. It's quick & easy.

Cannot run VS 2003 project using MSHTML, with .Net 2.0

P: n/a

Our application was build with VS 2003.
I have tried to run it on a computer with .Net 2.0 (but without .Net 1.1
, as it should be used)

and I got the following error -

System.InvalidCastException: Unable to cast COM object of type
'mshtml.HTMLBodyClass' to class type ''. 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.
at xxNamespace3.mcFontOrColorsChanged(Boolean isRefreshText)
...
at xxNamespace1.Main()

'-- error till here.

My relevant code:

Public Sub mcFontOrColorsChanged(ByVal isRefreshText As Boolean)
Dim doc As mshtml.HTMLDocument = ...
If (doc Is Nothing) Then Return
If (doc.all.length = 0) Then Return
If (doc.styleSheets Is Nothing) Then Return
If (doc.styleSheets.length = 0) Then Return
Dim docStyleSheet As mshtml.IHTMLStyleSheet =
CType(doc.styleSheets.item(0), mshtml.IHTMLStyleSheet)
Dim docStyleRules As mshtml.HTMLStyleSheetRulesCollection =
CType(docStyleSheet.rules, mshtml.HTMLStyleSheetRulesCollection)
... ' more code
Dim docBody As mshtml.HTMLBodyClass = CType(doc.body,
mshtml.HTMLBodyClass)
If Not (docBody Is Nothing) Then
... ' more code

'-- code till here.

My questions:
1. Why do I have casting problem only for 'mshtml.HTMLBodyClass' , but
no error for 'mshtml.IHTMLStyleSheet' casting ?
2. Will it help if I only change 'Microsoft.mshtml.dll' in my exe
directory ?
3. Where can I find 'Microsoft.mshtml.dll' for .Net 2.0 ?
4. Is there a link I can see the difference in MSHTML classes using .Net
2.0 vs. using .Net 1.1 ?
5. Did anyone else tried to run a VS 2003 app using MSHTML with .NET 2.0
? Did you have any problems ?
Thanks,
Atara.

*** Sent via Developersdex http://www.developersdex.com ***
Nov 21 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.