1

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?

BruceHill
  • 6,954
  • 8
  • 62
  • 114
  • 1
    I see two options here. Either create a new instance of Rug and call its SweepUnder method, or try to figure out what's actually causing the problem and fix it. Just because some random person on the Internet couldn't find the solution doesn't mean that you can't. Try to reduce your problem to the simplest example that reproduces the error. If you still can't figure it out, post your simplified code here so that we can all run it and reproduce the error for ourselves. – Mark Byers May 22 '12 at 18:11
  • I've spent a lot of time trying to solve this error, but its intermittent nature makes it difficult to debug. The problem is that I don't have the luxury of time at the moment, as this app needs to be deployed yesterday! (The story of a developers life!) That is not to say that I will not look at this problem further, and when I do I will post a separate question with an example. But the point of this question is this: _IS_ there a way to suppress the exception reporting as temporary quick fix so I can get my app deployed. If there is a Rug with a SweepUnder methdod, I will take it right now! – BruceHill May 22 '12 at 18:31

1 Answers1

1

I found the answer to my question one of the responses to this question:

How to use ThreadException?

Add this to the UnhandledException method to prevent the Windows crash notification from showing up:

Environment.Exit(1)

Thanks Hans Passant for this useful information.

Community
  • 1
  • 1
BruceHill
  • 6,954
  • 8
  • 62
  • 114
  • +1 for posting the solution, even though I hope you will fix it properly in the very near future. – Mark Byers May 22 '12 at 19:48
  • Thanks for the +1, Mark. I will create a separate question to deal with the exception properly in the near future. I will post a link to the question here when I do. Thanks again. – BruceHill May 22 '12 at 20:35