Debug a Failing Application #42
Chapter 5, Debugging
Windows Forms JIT Debugging
When you first try JIT debugging with a Windows Forms application, it
probably won’t work. By default, Windows Forms will display a dialog that
gives you the ability to see the details of the exception, continue, or quit, but
not the ability to attach a debugger to the process. To enable JIT debugging
with Windows Forms, you will need to add a configuration setting either to
the app.config of your application or, if you want to enable JIT debugging
for all Windows Forms applications, to the machine.config. To enable JIT
debugging, you need to add the following element inside the
< jitDebugging="true" />
This will enable JIT debugging either for the application (if you added it to
the app.config) or for all Windows Forms applications on your machine (if
you added it to the machine.config).
If your application does not already have an app.config, you
will need to create one by right-clicking on the project,
selecting Add New Item, and then selecting the application
configuration file from the list of files.
If you want to modify the machine.config file to enable JIT debugging for all
Windows Forms applications, the file can be found in the following direc-
The machine.config file actually already has this element—it simply needs to
be uncommented.
JIT Settings
A number of settings, in both Visual Studio and the registry, allow you to
control how JIT debugging works. The first way that you can configure JIT
debugging is through the Tool
Options window. Under the Debugging
folder is an item for JIT debugging, which is shown in Figure 5-32.
On this screen, you can disable JIT debugging for any of the various pro-
gram types. Disabling JIT debugging here overrides any settings in your con-
figuration files. When an exception is thrown, you will see a dialog stating
that JIT debugging is disabled.
A number of registry settings can also be used to configure JIT debugging
and the .NET framework. Both keys are located at:
Chapter 5, Debugging
#42 Debug a Failing Application
The first key is called DbgManagedDebugger and specifies what application
should be launched when an exception is detected. The default value for
this is vs7jit.exe, which launches the standard Visual Studio .NET JIT
debugger dialog that was shown in Figure 5-30. The second key is
DbgJITDebugLaunchSetting, which specifies what should be done when an
unhandled exception is caught. Table 5-1 shows the possible values for
this key.
Using the settings available in Visual Studio and the registry, you will be
able to configure JIT debugging to your specific needs.
Figure 5-32. Just-in-Time Debugging settings
Table 5-1. DbgJITDebugLaunchSetting key values
Value Behavior
0 Will prompt you with a dialog giving you two options:
Terminates the application
Calls the application specified in
1 Disables JIT debugging and passes control back to the application and the default
error handler.
2 Control is immediately passed to the application specified in
DbgManagedDebugger. This is the default behavior.

Get Visual Studio Hacks now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.