An unexpected error has occurred in TestApplication.exe.Select Quit and then restart this program, or select Details for more information.
result = i / j;
There is one thing to be aware of with regards to user interface threads. If your application happens to encounter an exception on the user interface thread, when you attach, the debugger may stop at the call to Application.Run(). For example, my example application encounters an exception during the click event handler (if the input data is invalid). If this occurs during your debugging, I suggest walking the call stack to find the first instance of your code and adding a call to Debug.Assert() to the method listed. I have included the stack trace from my example application below. The method highlighted in purple is where I will add the Debug.Assert() call.TestApplication.exeFormatExceptionat Number.ParseInt32()at Int32.Parse()at Int32.Parse()at MainForm.goButton_Click()at Control.OnClick()at Button.OnClick()at ButtonBase.WnProc()at EVL.EnterMainLoop()at Application.Run()at Program.Main()By adding the Debug.Assert(), possibly with a message to the user with instructions on how to proceed, the debugger can be attached prior to the exception. Once attached, the application is running under the debugger and debugging can take place when the exception occurs. When I add the Debug.Assert() and attach, I find that my application was failing to handle non-numeric strings being sent to Int32.Parse().With a Debug.Assert() added, the above steps become:
TestApplication.exeFormatExceptionat Number.ParseInt32()at Int32.Parse()at Int32.Parse()at MainForm.goButton_Click()at Control.OnClick()at Button.OnClick()at ButtonBase.WnProc()at EVL.EnterMainLoop()at Application.Run()at Program.Main()
Assertion FailedPlease call (###) ###-#### before continuing
It is important to note that you will need to have the matching symbols (.pdb) file for the application available on the PC that is running Visual Studio.Enjoy!-- DKDisclaimer(s):This posting is provided "AS IS" with no warranties, and confers no rights. Some of the information contained within this post may be in relation to beta software. Any and all details are subject to change.
PingBack from http://seanblogroll.aokhost.com/justintimedebugging.html