473,508 Members | 2,195 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

WebBrowser throws TargetInvocationException

I just got a TargetInvocationException from a WebBrowser control,
after calling
WebBrowser.Document.Write(text), which (internally) calls
System.Windows.Forms.HtmlDocument.Write(String text), which calls
System.Windows.Forms.UnsafeNativeMethods.IHTMLDocu ment2.Write(Object[]
psarray), which threw ArgumentException, because an index was out of
range in a dictionary object. This was stuffed into a
TargetInvocationException as its InnerException.

So what can we do? WebBrowser seems completely unreliable.

Guess we have to catch all exceptions from it.

Zytan

Apr 23 '07 #1
2 2474
Why does it seem unreliable? By your own admission, an index was out of
range, and an exception was thrown. Also, without seeing any of the code,
it's impossible to say if you were making the calls correctly or not.

You mention an index (of what I have no clue) being out of range. You
shouldn't be relying on an exception being thrown to tell you this. You
should be performing bounds checking yourself.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Zytan" <zy**********@gmail.comwrote in message
news:11*********************@l77g2000hsb.googlegro ups.com...
>I just got a TargetInvocationException from a WebBrowser control,
after calling
WebBrowser.Document.Write(text), which (internally) calls
System.Windows.Forms.HtmlDocument.Write(String text), which calls
System.Windows.Forms.UnsafeNativeMethods.IHTMLDocu ment2.Write(Object[]
psarray), which threw ArgumentException, because an index was out of
range in a dictionary object. This was stuffed into a
TargetInvocationException as its InnerException.

So what can we do? WebBrowser seems completely unreliable.

Guess we have to catch all exceptions from it.

Zytan

Apr 23 '07 #2
Why does it seem unreliable?

Because I've found about 5 major problems with it, so far, and it is
unreliable. I can't rely on it working properly. :)
By your own admission, an index was out of
range, and an exception was thrown. Also, without seeing any of the code,
it's impossible to say if you were making the calls correctly or not.
Yes, usually it's my fault. But, this time I'm just calling
WebBrowser.Document.Write() to append text to it, over and over, as
I've been doing the past month. This was the first time this
exception was thrown. Oh, and I am asking it to scroll to the bottom
and refresh after each write.
You mention an index (of what I have no clue) being out of range. You
shouldn't be relying on an exception being thrown to tell you this. You
should be performing bounds checking yourself.
The exception and innerexception was all inside of the Write() call,
all within the WebBrowser control. This is the culprit:

System.Windows.Forms.UnsafeNativeMethods.IHTMLDocu ment2.Write()

Whoever wrote that code didn't check the bounds.

Regardless, I now catch this exception and do nothing with it, since
what can I do? I'm phasing out the usage of WebBrowser. It just
amazes me how much is wrong with it. But, it is a web browser, after
all, so it is quite complex... I wouldn't want to write it.

Zytan

Apr 23 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
4866
by: Chuck | last post by:
When ever I try to implement an ImageList, I always get an exception when the application runs. The ImageList doesn't even have to be used by anything. An empty ImageList doesn't throw! The...
0
3663
by: Mike Schilling | last post by:
I have some code that calls methods reflectively (the method called and its parameters are determined by text received in a SOAP message, and I construct a map from strings to MethodInfos). The...
0
7920
by: chaf2701 | last post by:
Hi, I was in trouble with the System.Windows.Forms.ImageList control from VC.NET. I was doing the following : 1. New Project, C#, Windows Application 2. Add ImageList component imageList1 to...
4
7528
by: Aren Cambre | last post by:
Why does SmtpMail.Send throw an exception if the MailMessage's BodyFormat = MailFormat.Html? I've searched all over the place and cannot find a solution anywhere. I am running this on Windows XP...
4
2981
by: Julia | last post by:
Hi Everyone, I am using webbrowser control to post data to an aspx page. However, for some reason, the aspx page sometimes will execute page_load event twice, and sometimes execute it once. So I...
1
1380
by: Jason Tost | last post by:
Good afternoon, I was wondering if there is a way you can determine what the security requirements are of a control. I have an application that throws a security exception if there is a...
0
2130
by: Jocker | last post by:
Hi Group I'm writing an Internet Explorer plugin. Everything works well, except when I try to handle the onscroll event....
0
1690
by: Jocker | last post by:
I'll try reposting this message with the hope someone can help me with this issue. PS: is this the right newsgroup for this question? --- Hi Group I'm writing an Internet Explorer plugin....
1
4268
by: Zytan | last post by:
if (webBrowserControl.Document == null) is throwing an InvalidCastException. PLEASE NOTE: ***The function being called is being called from a thread OTHER THAN than the one that created the...
0
7331
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7391
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7054
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7501
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5633
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3188
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1564
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
768
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
424
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.