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

InvalidOperationException appeared after introduction of WebBrowser control

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.