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
<system.windows.forms 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
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: