473,232 Members | 1,546 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,232 software developers and data experts.

InvalidOperationException appeared after introduction of WebBrowser control

We are experiencing a tuff-to-debug problem ever since we introduced a
WebBrowser control into our failry large application. I'm not sure if
the problem description below contains enough details, so if I need to
elaborate on something please ask for it.

We have a UserControl with a WebBrowser on it. This UserControl is
instantiated a few times during the program run, depending on user
interaction. The WebBrowser then navigates to a local HTML file. I
catch the navigating event and always cancel it, instead taking some
custom action.

At irregular and hard-to-reproduce times, we get an
InvalidOperationException when closing the application. The debugger
is not able to open a code file where it happens, it just shows a
popup with the exception. Here's a trace:

------------------------- TRACE -------------------------------

System.Windows.Forms.Control.MarshaledInvoke(Contr ol caller, Delegate
method, Object[] args, Boolean synchronous)
at System.Windows.Forms.Control.BeginInvoke(Delegate method,
Object[] args)
at
System.Windows.Forms.WindowsFormsSynchronizationCo ntext.Post(SendOrPostCallback
d, Object state)
at System.Windows.Forms.AxHost.ConnectionPointCookie. Finalize()</
StackTrace><ExceptionString>System.InvalidOperatio nException: Invoke
or BeginInvoke cannot be called on a control until the window handle
has been created.
at System.Windows.Forms.Control.MarshaledInvoke(Contr ol caller,
Delegate method, Object[] args, Boolean synchronous)
at System.Windows.Forms.Control.BeginInvoke(Delegate method,
Object[] args)
at
System.Windows.Forms.WindowsFormsSynchronizationCo ntext.Post(SendOrPostCallback
d, Object state)
at System.Windows.Forms.AxHost.ConnectionPointCookie. Finalize()</
ExceptionString></Exception></TraceRecord>
The program '[2648] MyApplication.vshost.exe: Managed' has exited with
code 0 (0x0).
------------------------------------------------------------------------

It almost seems like the 'Finalize' method of the webbrowser's
ConnectionPointCookie is being called twice (?).
Is there any way to check this?
Should I be looking for a solution/the problem in different parts of
the code?

Jun 8 '07 #1
2 4252
Jeroen,

I'm thinking it is something else you are doing somewhere else in the
code.

Are you doing anything on another thread, and possibly calling the
webbrowser control then?

Also, the custom actions you are taking when you call Navigate, can you
perform those actions using an asynchronous pluggable protocol?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Jeroen" <me******@gmail.comwrote in message
news:11**********************@p47g2000hsd.googlegr oups.com...
We are experiencing a tuff-to-debug problem ever since we introduced a
WebBrowser control into our failry large application. I'm not sure if
the problem description below contains enough details, so if I need to
elaborate on something please ask for it.

We have a UserControl with a WebBrowser on it. This UserControl is
instantiated a few times during the program run, depending on user
interaction. The WebBrowser then navigates to a local HTML file. I
catch the navigating event and always cancel it, instead taking some
custom action.

At irregular and hard-to-reproduce times, we get an
InvalidOperationException when closing the application. The debugger
is not able to open a code file where it happens, it just shows a
popup with the exception. Here's a trace:

------------------------- TRACE -------------------------------

System.Windows.Forms.Control.MarshaledInvoke(Contr ol caller, Delegate
method, Object[] args, Boolean synchronous)
at System.Windows.Forms.Control.BeginInvoke(Delegate method,
Object[] args)
at
System.Windows.Forms.WindowsFormsSynchronizationCo ntext.Post(SendOrPostCallback
d, Object state)
at System.Windows.Forms.AxHost.ConnectionPointCookie. Finalize()</
StackTrace><ExceptionString>System.InvalidOperatio nException: Invoke
or BeginInvoke cannot be called on a control until the window handle
has been created.
at System.Windows.Forms.Control.MarshaledInvoke(Contr ol caller,
Delegate method, Object[] args, Boolean synchronous)
at System.Windows.Forms.Control.BeginInvoke(Delegate method,
Object[] args)
at
System.Windows.Forms.WindowsFormsSynchronizationCo ntext.Post(SendOrPostCallback
d, Object state)
at System.Windows.Forms.AxHost.ConnectionPointCookie. Finalize()</
ExceptionString></Exception></TraceRecord>
The program '[2648] MyApplication.vshost.exe: Managed' has exited with
code 0 (0x0).
------------------------------------------------------------------------

It almost seems like the 'Finalize' method of the webbrowser's
ConnectionPointCookie is being called twice (?).
Is there any way to check this?
Should I be looking for a solution/the problem in different parts of
the code?

Jun 8 '07 #2
Nope, the webbrowser is just instantiated, and not referenced in other
code. I will be looking into asynchronous pluggable protocols right
after this. Thanks for the tip.

I'm also posting because I thought I had a solution (so maybe this
post will help folks with a simular problem a little bit). In the user
control containing the webbrowser, I now dispose the webbrowser
control manually. This seemed to solve the problem: we get almost no
exceptions in debug mode anymore. However, during tests with a release
build of the software we are re-experiencing this
InvalidOperationException (much less frequent but still (seemingly)
irregularly, also at closing the application).

The dispose method of the usercontrol now looks like this:

/***********************************/
protected override void Dispose( bool disposing )
{
// The following statement improves things
// a lot, but in release mode there still are
// some InvalidOperationExceptions
this.myWebBrowser.Dispose();

if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
/**********************************/

Jun 11 '07 #3

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

Similar topics

9
by: ASP .NET Newbie | last post by:
How can I run a WebBrowser control using ASP.NET/VB.NET? I know I can use the WebClient to get the page data, but I need to be able to use the WebBrowser (AxWebBrowser)? Thanks, Chad
1
by: Tuong | last post by:
I have a situation where i have a form that contains a webbrowser control. With this I was able to implement an application that can browse websites. One particular website i visited opens up...
12
by: Alex Clark | last post by:
Greetings, (.NET 2.0, WinXP Pro/Server 2003, IE6 with latest service packs). I've decided to take advantage of the layout characteristics of HTML documents to simplify my printing tasks, but...
2
by: jasonhartsoe | last post by:
I'm using Visual Studio 2005 Team Edition....using visual basic. I'm trying to use the webbrowser control. In the webbrowser control I have it got to a page where there is a form. It waits for...
11
by: Anil Gupte | last post by:
....and how do I insert one into my form? I used in VB 6.0 last, but cannot figure out where it is in .Net Thanx, -- Anil Gupte www.keeninc.net www.icinema.com
4
by: Steve Richter | last post by:
I would like to build an HTML stream as a string and have the WebBrowser control render that HTML. Then on PostBack, or whatever it is called, I would like my code to be the one that receives what...
6
by: Leon | last post by:
Hi there, I am trying to use the WebBrowser Control in a form which is being started in an own thread by the main form of my application. Unfortunately I am always getting an error in...
2
by: jim | last post by:
Has anyone seen a way to read the data stream for a URL being navigated to by a webbrowser control and edit it (i.e. search HTML stream for and possibly remove objectionable language for a kid's...
0
by: scottietrek | last post by:
I have a webbrowser control that allows me to save username and password infromation for a proxy server and i have been successful in changing the system default proxy for my application. What i now...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

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.