Unable to case COM object of type mshtml.HTMLDocumentClass to interface type mshtml.DispHTMLDocument

Add-in Express™ Support Service
That's what is more important than anything else

Unable to case COM object of type mshtml.HTMLDocumentClass to interface type mshtml.DispHTMLDocument
 
George Weihs




Posts: 13
Joined: 2009-07-28
Hi, I am using AIX for IE 2010 (puchased last month) and I am having a problem that occurs only on some PCs. The error occurs when i call the GetHTML method on the IEModule class below.

The exception says "Unable to cast COM object of type mshtml.HTMLDocumentClass to interface type mshtml.DispHTMLDocument. This operation failed because the QueryInterface call on the COM object..."

It works on many machines i have tested here. But my customer consistently gets this error on all machines they try. The customer is using IE8 (and so am I). Any ideas?



[ComVisible(true), Guid("A632A78C-D297-4F5B-B731-8A94A836B093")]
public class IEModule : AddinExpress.IE.ADXIEModule
{
public IEModule()
{
InitializeComponent();
}

public IEModule(IContainer container)
{
container.Add(this);

InitializeComponent();
}


#region ADX automatic code

// Required by Add-in Express - do not modify
// the methods within this region

public override System.ComponentModel.IContainer GetContainer()
{
if (components == null)
components = new System.ComponentModel.Container();
return components;
}

[ComRegisterFunctionAttribute]
public static void RegisterIEModule(Type t)
{
AddinExpress.IE.ADXIEModule.RegisterIEModuleInternal(t);
}

[ComUnregisterFunctionAttribute]
public static void UnregisterIEModule(Type t)
{
AddinExpress.IE.ADXIEModule.UnregisterIEModuleInternal(t);
}

[ComVisible(true)]
public class IECustomContextMenuCommands :
AddinExpress.IE.ADXIEModule.ADXIEContextMenuCommandDispatcher
{
}

[ComVisible(true)]
public class IECustomCommands :
AddinExpress.IE.ADXIEModule.ADXIECommandDispatcher
{
}

#endregion

public IE.WebBrowser IEApp
{
get
{
return (this.IEObj as IE.WebBrowser);
}
}

public mshtml.HTMLDocument HTMLDocument
{
get
{
return (this.HTMLDocumentObj as mshtml.HTMLDocument);
}
}


public string GetHTML()
{

return HTMLDocument.documentElement.outerHTML;

}

}
Posted 14 Apr, 2011 15:27:37 Top
Sergey Grischenko


Add-in Express team


Posts: 7233
Joined: 2004-07-05
Hi George,

Is the problematic PC up to date? Please try to use the code below:

public string GetHTML()
{
if (HTMLDocument.documentElement is mshtml.IHTMLDocument)
{
return HTMLDocument.documentElement.outerHTML;
}
}
Posted 15 Apr, 2011 08:07:05 Top
gweihs




Posts: 13
Joined: 2009-07-28
What do mean, is it "up to date"? Remember, its not just 1 PC its all PCs at a given customer location (which i assume are all configured similarly).
Posted 15 Apr, 2011 11:27:34 Top
gweihs




Posts: 13
Joined: 2009-07-28
I can see how your code snippet might remove the casting error, but what do i do for an else statement?
Posted 15 Apr, 2011 11:30:37 Top
Sergey Grischenko


Add-in Express team


Posts: 7233
Joined: 2004-07-05
Hi George,

You can do nothing, there is no available HTML document. It may happen if the user opens a web page that hosts an ActiveX object (e.g. a PDF document).
Posted 18 Apr, 2011 12:29:06 Top
gweihs




Posts: 13
Joined: 2009-07-28
Sergey,

Thanks for the reply. I don't know if it applies, however, because I know the web page we are working with - its always the same web page (html). On my machines here, it works fine. But the same web page DOES NOT work at my customer location.

What are the different types referred to by the error message: mshtml.HTMLDocumentClass and mshtml.DispHTMLDocument?

Are you saying that there is a valid scenario where the HTMLDocument.documentElement could be of a different type?
Posted 18 Apr, 2011 14:36:40 Top
Sergey Grischenko


Add-in Express team


Posts: 7233
Joined: 2004-07-05
Hi George,

You can see differences in the Object Browser of Visual Studio.
The error message says that the object doesn't implement the DispHTMLDocument interface. Probably there are any errors in the HTML code. Can you please send me a link to the problematic web page?
Posted 19 Apr, 2011 05:42:46 Top
gweihs




Posts: 13
Joined: 2009-07-28
Hi Sergey;

Thanks for your continued efforts with this problem. It is still a mystery to me. I am unable to attach a debugger in this environment, so its tough to diagnose, but here is what i know to date:

1) I am having no problems in any of my test environments. These environments are XP and IE8, just like the problem PCs.

2) On the PCs that are having the problem (all at same customer), the casting error happens as described above. They are all running XP and IE8. My application required .NET 2.0 but the users may have newer versions of .NET installed as well.


3) I have added some code to display the TYPE of the HTMLDocumentObj member and it returns type type "mshtml.HTMLDocumentClass". That Type is the same as I see on working desktops.

4) As stated earlier, this problem occurs on all desktops at this one customer and on *ALL* web pages that we try. This would make me think its a configuration problem, not specific to one web page. It makes we wonder about mshtml version issues?

5) My windows installer setup installs my program. Then, on first run, my program runs the setup for the IEAddOn which sucessfully installs in a separate folder under Program Files/MyCompany folder. After installation, Microsoft.mshtml.dll is found in the IEAddOn folder, but its not distributed in my main folder. Since this works fine in my environments, I assume that I don't need it. But I have tried copying the mshtml dll to my application folder but the problem persists.

Are there version issues I need to be concerned about with Microsoft.mshtml.dll? Should i run the PIA_resdist or something?

Please help. This problem has been going on for weeks and the customer is losing patience.

My gut tells me that this problem is a version problem with mshtml. Maybe my test environments already have it installed, but this customer site does not. Or visa versa. Your help with this would be greatly appreciated.
Posted 01 May, 2011 15:00:38 Top
Sergey Grischenko


Add-in Express team


Posts: 7233
Joined: 2004-07-05
Hi George,

Please ask the user to check if all the latest Windows updates are installed on his PC.
What version of MSHTML do you use in your project?
Did you select the Version-neutral (IE6 and higher) option in the New IE Add-on wizard when you created your project?
Posted 02 May, 2011 05:43:30 Top
gweihs




Posts: 13
Joined: 2009-07-28
Sergey;

The users says yes, they are running XP with latest SP.

How do i know what version of MSHTML I use in my project? Can you tell me how to find out.

How do i know whether my project was created using version neutral (IE6 or higher) option in the wizard. How can I inspect the project and find out.

Also -this has been going very slowly. I am very disappointed with the support i am receiving here. The time shift between us creates a smaller window for back-and-forth and therefore slowing us down considerably. I need you to be more complete with your responses.

I need you to tell me what to do to resolve this.
Posted 09 May, 2011 16:58:11 Top