Debug using the Only-In-Time Debugger in Visual Studio

Applies to: yesVisual Studio noVisual Studio for Mac noVisual Studio Code

Merely-In-Time debugging can launch Visual Studio automatically when an app running outside Visual Studio errors or crashes. With But-In-Fourth dimension debugging, you tin can examination apps exterior of Visual Studio, and open Visual Studio to begin debugging when a problem occurs.

But-In-Time debugging works for Windows desktop apps. It does not work for Universal Windows Apps, or for managed code that is hosted in a native application, such as Visualizers.

Tip

If you just desire to stop the Only-In-Time Debugger dialog box from appearing, just don't have Visual Studio installed, see Disable the Merely-In-Time Debugger. If you once had Visual Studio installed, you lot may demand to disable Merely-In-Time debugging from the Windows registry.

Enable or disable Just-In-Time debugging in Visual Studio

Notation

To enable or disable Just-In-Time debugging, you must be running Visual Studio as an ambassador. Enabling or disabling Simply-In-Time debugging sets a registry cardinal, and administrator privileges may be required to alter that key. To open up Visual Studio equally an ambassador, right-click the Visual Studio app and choose Run as administrator.

Yous tin can configure Just-In-Time debugging from the Visual Studio Tools > Options (or Debug > Options) dialog box.

To enable or disable But-In-Time debugging:

  1. On the Tools or Debug carte, select Options > Debugging > Only-In-Time.

    Enable or disable JIT debugging

  2. In the Enable Just-In-Time debugging for these types of code box, select the types of code y'all want Only-In-Fourth dimension debugging to debug: Managed, Native, and/or Script.

  3. Select OK.

If you enable the Just-In-Time debugger, but it doesn't open when an app crashes or errors, run into Troubleshoot But-In-Time debugging.

Disable Just-In-Time debugging from the Windows registry

Just-In-Fourth dimension debugging may yet be enabled even if Visual Studio is no longer installed on your calculator. If Visual Studio is no longer installed, y'all can disable Just-In-Time debugging past editing the Windows registry.

To disable But-In-Time debugging by editing the registry:

  1. From the Windows Start menu, run the Registry Editor (regedit.exe).

  2. In the Registry Editor window for 64-bit computers, locate and delete the following registry entries:

    • HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\.NETFramework\DbgManagedDebugger

    • HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows NT\CurrentVersion\AeDebug\Debugger

    JIT registry key

  3. If the post-obit registry entries are present, or your computer is running a 32-scrap operating arrangement, delete the following entries:

    • HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\DbgManagedDebugger

    • HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AeDebug\Debugger

    Brand sure non to delete or change any other registry keys.

  4. Shut the Registry Editor window.

Enable Just-In-Time debugging of a Windows Form

Past default, Windows Form apps have a top-level exception handler that lets the app keep running if it can recover. If a Windows Forms app throws an unhandled exception, it shows the post-obit dialog:

Windows Form unhandled exception

To enable Only-In-Time debugging instead of standard Windows Class error treatment, add together these settings:

  • In the system.windows.forms section of the car.config or <app name>.exe.config file, set the jitDebugging value to truthful:

                      <configuration>     <system.windows.forms jitDebugging="true" /> </configuration>                                  
  • In a C++ Windows Grade application, also set up DebuggableAttribute to truthful in a .config file or in your lawmaking. If yous compile with /Zi and without /Og, the compiler sets this attribute for you. If you want to debug a non-optimized release build, notwithstanding, you lot must gear up DebuggableAttribute by adding the following line in your app'southward AssemblyInfo.cpp file:

                      [assembly:Organisation::Diagnostics::DebuggableAttribute(truthful, true)];                                  

    For more data, come across DebuggableAttribute.

Use Only-In-Time debugging

This example walks you through Just-In-Time debugging when an app throws an fault.

  • You lot must accept Visual Studio installed to follow these steps. If you don't have Visual Studio, you can download the gratis Visual Studio Community Edition.

  • Make sure Just-In-Time debugging is enabled in Tools > Options > Debugging > Just-In-Fourth dimension.

For this instance, you'll brand a C# console app in Visual Studio that throws a NullReferenceException.

  1. In Visual Studio, create a C# console app (File > New > Projection > Visual C# > Console Application) named ThrowsNullException. For more information about creating projects in Visual Studio, see Walkthrough: Create a simple application.

  2. When the projection opens in Visual Studio, open up the Programme.cs file. Replace the Main() method with the following code, which prints a line to the console and and so throws a NullReferenceException:

                      static void Chief(cord[] args) {     Console.WriteLine("we volition now throw a NullReferenceException");     throw new NullReferenceException("this is the exception thrown by the panel app"); }                                  
  3. To build the solution, choose either the Debug (default) or Release configuration, and and so select Build > Rebuild Solution.

    Notation

    • Choose Debug configuration for the total debugging experience.
    • If you select Release configuration, you must plough off Just My Code for this procedure to piece of work. Under Tools > Options > Debugging, deselect Enable Simply My Code.

    For more than data about build configurations, run into Agreement build configurations.

  4. Open the built app ThrowsNullException.exe in your C# project folder (...\ThrowsNullException\ThrowsNullException\bin\Debug or ...\ThrowsNullException\ThrowsNullException\bin\Release).

    Yous should see the following command window:

    Screenshot of the console for ThrowsNullException.exe, which throws an unhandled null reference exception (System.NullReferenceException).

  5. The Choose Merely-In-Time Debugger dialog opens.

    Screenshot of the Choose Just-In-Time Debugger dialog box, which appears after the exception appears in the ThrowsNullException.exe console window.

    Nether Available Debuggers, select New instance of <your preferred Visual Studio version/edition>, if not already selected.

  6. Select OK.

    The ThrowsNullException project opens in a new case of Visual Studio, with execution stopped at the line that threw the exception:

    Screenshot of the ThrowsNullException project in Visual Studio, with highlighting of the line of source code that threw the exception.

Y'all can commencement debugging at this signal. If you were debugging a real app, y'all would need to find out why the code is throwing the exception.

Circumspection

If your app contains untrusted lawmaking, a security warning dialog box appears, enabling y'all to decide whether to proceed with debugging. Before you go along debugging, determine whether you trust the lawmaking. Did you write the code yourself? If the application is running on a remote car, do y'all recognize the name of the process? If the app is running locally, consider the possibility of malicious code running on your computer. If you make up one's mind the code is trustworthy, select OK. Otherwise, select Cancel.

Troubleshoot Just-In-Time debugging

If Just-In-Fourth dimension debugging doesn't start when an app crashes, fifty-fifty though it is enabled in Visual Studio:

  • Windows Error Reporting could be taking over the mistake handling on your figurer.

    To fix this issue, use Registry Editor to add a DWORD Value of Disabled, with Value information of i, to the post-obit registry keys:

    • HKEY_LOCAL_MACHINE\Software\WOW6432Node\Microsoft\Windows\Windows Error Reporting

    • (For 32-bit machines) HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\Windows Mistake Reporting

    For more information, see .WER settings.

  • A known Windows issue may be causing the But-In-Time debugger to fail.

    The prepare is to add a DWORD Value of Auto, with Value data of 1, to the post-obit registry keys:

    • HKEY_LOCAL_MACHINE\Software\WOW6432Node\Microsoft\Windows NT\CurrentVersion\AeDebug

    • (For 32-fleck machines) HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AeDebug

You might see the following fault messages during But-In-Time debugging:

  • Unable to attach to the crashing process. The specified program is not a Windows or MS-DOS program.

    The debugger tried to attach to a procedure running under some other user.

    To work around this problem, in Visual Studio, open Debug > Attach to Process (or press Ctrl + Alt + P), and find the process you desire to debug in the Available Processes listing. If you lot do non know the name of the procedure, observe the Process ID in the Visual Studio Just-In-Fourth dimension Debugger dialog. Select the process in the Bachelor Processes list, and select Attach. Select No to dismiss the Only-In-Fourth dimension debugger dialog.

  • Debugger could not be started because no user is logged on.

    There is no user logged onto the console, so there is no user session to display the Just-In-Time debugging dialog.

    To ready this trouble, log onto the machine.

  • Class non registered.

    The debugger tried to create a COM grade that is not registered, probably due to an installation problem.

    To prepare this problem, use the Visual Studio Installer to reinstall or repair your Visual Studio installation.

Run across also

  • Debugger security
  • First look at the debugger
  • Options, Debugging, Merely-In-Time dialog box
  • Security Warning: Attaching to a process owned past an untrusted user can be dangerous. If the post-obit information looks suspicious or you are unsure, do not attach to this process