Problem Accessing HTMLElementCollection

  • Thread starter Thread starter Tom Bean
  • Start date Start date
T

Tom Bean

I developed a C# application to automate input to elements of a web page
displayed in an AxWebBrowser control. The app calls GetEnumerator() on the
HTMLDocument's HTMLElementCollection (i.e. HTMLDocument.all) to walk
elements of the document.

This works perfectly on my development system with both Debug and Release
builds, however, when I deploy the app to a client system running Windows XP
Professional, it doesn't work.

I added logging to the app to find out what was happening on the client
system and found that GetType() returns '__ComObject' for all elements with
the exception of the HTMLBodyClass element.

I have checked IE settings and the versions of the DLLs my app uses on my
development system and the client system and can find no differences except
Microsoft.mshtml running on my development system is located in the GAC
while it is running from my installation directory on the client.

What do I need to do to get the client installation to work?

Thanks,
Tom
 
Tom,

You haven't said how it doesn't work on these other machines.

BTW, GetType is returning the correct type when you check the type of
these objects. This is what is returned by ToString for any type deriving
from System.__ComObject (which is what you are using when you use the
interop assemblies for MSHTML).

What are the details of the exception you are getting?
 
Nicholas,

On my development system, GetType().Name returns the type of the element,
for example, "HTMLInputElement" but on the client systems GetType().Name is
always "__ComObject".

I don't get any exception but when I make the comparison, if
(element.GetType().Name == "HTMLInputElement"), it always fails because
"__ComObject" is being returned as the type name.

Tom

Nicholas Paldino said:
Tom,

You haven't said how it doesn't work on these other machines.

BTW, GetType is returning the correct type when you check the type of
these objects. This is what is returned by ToString for any type deriving
from System.__ComObject (which is what you are using when you use the
interop assemblies for MSHTML).

What are the details of the exception you are getting?


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Tom Bean said:
I developed a C# application to automate input to elements of a web page
displayed in an AxWebBrowser control. The app calls GetEnumerator() on
the HTMLDocument's HTMLElementCollection (i.e. HTMLDocument.all) to walk
elements of the document.

This works perfectly on my development system with both Debug and Release
builds, however, when I deploy the app to a client system running Windows
XP Professional, it doesn't work.

I added logging to the app to find out what was happening on the client
system and found that GetType() returns '__ComObject' for all elements
with the exception of the HTMLBodyClass element.

I have checked IE settings and the versions of the DLLs my app uses on my
development system and the client system and can find no differences
except Microsoft.mshtml running on my development system is located in
the GAC while it is running from my installation directory on the client.

What do I need to do to get the client installation to work?

Thanks,
Tom
 
Tom,

Have you distributed the interop libraries as well that you are using to
access the HTML document model?


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Tom Bean said:
Nicholas,

On my development system, GetType().Name returns the type of the element,
for example, "HTMLInputElement" but on the client systems GetType().Name
is always "__ComObject".

I don't get any exception but when I make the comparison, if
(element.GetType().Name == "HTMLInputElement"), it always fails because
"__ComObject" is being returned as the type name.

Tom

Nicholas Paldino said:
Tom,

You haven't said how it doesn't work on these other machines.

BTW, GetType is returning the correct type when you check the type of
these objects. This is what is returned by ToString for any type
deriving from System.__ComObject (which is what you are using when you
use the interop assemblies for MSHTML).

What are the details of the exception you are getting?


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Tom Bean said:
I developed a C# application to automate input to elements of a web page
displayed in an AxWebBrowser control. The app calls GetEnumerator() on
the HTMLDocument's HTMLElementCollection (i.e. HTMLDocument.all) to walk
elements of the document.

This works perfectly on my development system with both Debug and
Release builds, however, when I deploy the app to a client system
running Windows XP Professional, it doesn't work.

I added logging to the app to find out what was happening on the client
system and found that GetType() returns '__ComObject' for all elements
with the exception of the HTMLBodyClass element.

I have checked IE settings and the versions of the DLLs my app uses on
my development system and the client system and can find no differences
except Microsoft.mshtml running on my development system is located in
the GAC while it is running from my installation directory on the
client.

What do I need to do to get the client installation to work?

Thanks,
Tom
 
Nicholas,

I am distributing: AxInterop.SHDocVw.dll, Interop.SHDocVw.dll, and
Microsoft.mshtml.dll.

Tom

Nicholas Paldino said:
Tom,

Have you distributed the interop libraries as well that you are using
to access the HTML document model?


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Tom Bean said:
Nicholas,

On my development system, GetType().Name returns the type of the element,
for example, "HTMLInputElement" but on the client systems GetType().Name
is always "__ComObject".

I don't get any exception but when I make the comparison, if
(element.GetType().Name == "HTMLInputElement"), it always fails because
"__ComObject" is being returned as the type name.

Tom

Nicholas Paldino said:
Tom,

You haven't said how it doesn't work on these other machines.

BTW, GetType is returning the correct type when you check the type of
these objects. This is what is returned by ToString for any type
deriving from System.__ComObject (which is what you are using when you
use the interop assemblies for MSHTML).

What are the details of the exception you are getting?


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

I developed a C# application to automate input to elements of a web page
displayed in an AxWebBrowser control. The app calls GetEnumerator() on
the HTMLDocument's HTMLElementCollection (i.e. HTMLDocument.all) to walk
elements of the document.

This works perfectly on my development system with both Debug and
Release builds, however, when I deploy the app to a client system
running Windows XP Professional, it doesn't work.

I added logging to the app to find out what was happening on the client
system and found that GetType() returns '__ComObject' for all elements
with the exception of the HTMLBodyClass element.

I have checked IE settings and the versions of the DLLs my app uses on
my development system and the client system and can find no differences
except Microsoft.mshtml running on my development system is located in
the GAC while it is running from my installation directory on the
client.

What do I need to do to get the client installation to work?

Thanks,
Tom
 
Hi

If you include the mshtml in your project, and the .NET setup project will
check the dependency to including the mshtml.dll.
And you can set to deploy the mshtml into GAC and check the register to
true to make sure the mshtml is deployed correctly in the GAC.

Deploying an Interop Application
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/htm
l/cpcondeployinginteropapplication.asp

Here is a general link about deploy .net application.
Deploying Applications
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/htm
l/cpconDeployingNETFrameworkApplications.asp

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Peter,

I already have Microsoft.mshtml in my project, however, I did the following
to add mshtml to the project also.

I added a reference to mshtml to my project by selecting "Microsoft HTML
Object Library" from the COM tab of the "Add Reference" dialog, however, it
just points to Microsoft.mshtml, which I already have a reference to,
installed in the GAC. As a consequence of adding it again, I got a lot of
warnings about various mshtml elements being defined in multiple places.

I also tried adding a reference to C::\Windows\System32\mshtml.dll but got
an error message saying "A reference ti 'C::\Windows\System32\mshtml.dll'
could not be added. This is not a valid assembly or COM component. Only
assemblies with extension 'dll' and COM components can be referenced.
Please make sure that the file is accessible, and that it is a valid
assembly or COM component."

I checked the GAC on my development system and there is no reference to
mshtml other than Microsoft.mshtml installed in it. I aslo used GACUtil to
add Microsoft.mshtml to the GAC on a client system but it still sees all the
HTMLElements as __COMObjects.

The client system has Internet Explorer installed and has the same version
of mshtml.dll installed in C::\Windows\System32 as I do on my development
system. I also installed my app on another system with Visual Studio
installed and it works as expected.

Are you talking about some other mshtml that I need to add to my project?
Is there something I missed or have done incorrectly while adding mshtml?

Thanks,
Tom
 
Hi

Based on my test with the simple code below, the setup project will works
on a non VS.NET installed machine.
You may try the simple sample first to see if that works for you.

private void Form1_Load(object sender, System.EventArgs e)
{
this.axWebBrowser1.Navigate("www.google.com");
}

private void button1_Click(object sender, System.EventArgs e)
{
mshtml.HTMLDocument doc= (mshtml.HTMLDocument)axWebBrowser1.Document;
MessageBox.Show(doc.title);
}

Also mshtml.dll will be shipped with IE, you may try to update the client
with the newest IE to fresh the mshtml.dll.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Peter,

When the problem showed up, I checked the version of IE on the client and it
is the same as on my development system, the latest.

The problem isn't with accessing the HTMLDocument. It just happens when my
app enumerates the HTMLElementCollection returned by
HTMLDocument.all.GetEnumerator(). The element types are always
'__COMObject'.

Tom
 
Hi

Thanks for your quickly reply!
Unfortunately, I still can not reproduce the problem.

Here is my test code.
private void Form1_Load(object sender, System.EventArgs e)
{
this.axWebBrowser1.Navigate("www.google.com");
}

private void button1_Click(object sender, System.EventArgs e)
{
mshtml.HTMLDocument doc= (mshtml.HTMLDocument)axWebBrowser1.Document;
foreach(object o in doc.all)
Console.WriteLine(o.GetType().Name);
}

The code will print out the type name, even if after I installed into a
windows xp+.NET 1.1 without visual studio installed.
You may try the code above, if the problem persists, I think the problem
may need create dump or live debugging which is provided by MSPSS.
You may reach MSPSS via the link below.
http://support.microsoft.com

BTW: if you have no concern, I suggest you reinstall the .NET framework to
see if that works.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Was this problem even got resolve? Now I am having the same problem.

Thanks
 
is this problem even got resolve? I am having the same issue here.

thanks
 
Hi,

How you resolved finally this issue? I am facing same problem. Please
help me out.

Thanks,
Hitesh.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top