I have a VB.Net WinForms application that throws an exception when the application exits. The exception only occurs on closing the application and in no way affects the functioning of the application. The exception thrown is InvalidOperationException and the debugger is not able to identify where the exception is occurring, rather in Visual Studio 2008 the exception is shown in a popup window without referencing a line number.
Here is someone else that has exactly the same issue: http://bytes.com/topic/c-sharp/answers/659366-invalidoperationexception-appeared-after-introduction-webbrowser-control
As mentioned in this link, the exception is intermittant, but is somehow related to the WebBrowser control, because the exception on exiting the application only occurs when at least 2 forms with WebBrowser controls on them have been shown. (Or one form with a WebBrowser control opened and closed twice.)
Now in VB.Net I am able to catch the exception in the AppDomain.CurrentDomain.UnhandledException handler, but the only way I have managed to stop Windows from reporting the exception is to use MessageBox to show a message in the handler. If I leave off the MessageBox.Show call in the handler then the exception is reported when the application closes.
Does anyone know a way that I can suppress this exception in the UnhandledException handler so that the application will always exit cleanly?