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

Applies to: yesVisual Studio noVisual Studio for Mac

But-In-Time debugging can launch Visual Studio automatically when an app running exterior Visual Studio errors or crashes. With Just-In-Time debugging, you can test apps outside of Visual Studio, and open up 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 only want to finish the Just-In-Time Debugger dialog box from actualization, only don't have Visual Studio installed, come across Disable the Just-In-Time Debugger. If you once had Visual Studio installed, you may demand to disable Simply-In-Fourth dimension debugging from the Windows registry.

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

Note

To enable or disable Just-In-Time debugging, y'all must exist running Visual Studio as an administrator. Enabling or disabling Merely-In-Time debugging sets a registry key, and administrator privileges may exist required to alter that key. To open Visual Studio every bit an administrator, right-click the Visual Studio app and choose Run as ambassador.

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

To enable or disable But-In-Fourth dimension debugging:

  1. On the Tools or Debug menu, select Options > Debugging > Just-In-Fourth dimension.

    Enable or disable JIT debugging

  2. In the Enable But-In-Time debugging for these types of code box, select the types of code you want Merely-In-Time debugging to debug: Managed, Native, and/or Script.

  3. Select OK.

If yous enable the Just-In-Time debugger, just it doesn't open when an app crashes or errors, see Troubleshoot Just-In-Time debugging.

Disable Only-In-Time debugging from the Windows registry

Just-In-Fourth dimension debugging may all the same be enabled fifty-fifty if Visual Studio is no longer installed on your calculator. If Visual Studio is no longer installed, you tin disable But-In-Fourth dimension debugging by editing the Windows registry.

To disable Just-In-Time debugging past editing the registry:

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

  2. In the Registry Editor window for 64-scrap computers, locate and delete the post-obit 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 following registry entries are present, or your computer is running a 32-bit operating system, delete the post-obit entries:

    • HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\DbgManagedDebugger

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

    Make certain not to delete or alter whatever other registry keys.

  4. Shut the Registry Editor window.

Enable Just-In-Time debugging of a Windows Class

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 Just-In-Time debugging instead of standard Windows Form mistake handling, add these settings:

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

                      <configuration>     <system.windows.forms jitDebugging="true" /> </configuration>                                  
  • In a C++ Windows Grade application, as well ready DebuggableAttribute to true in a .config file or in your code. If you compile with /Zi and without /Og, the compiler sets this attribute for yous. If you want to debug a not-optimized release build, however, you must set DebuggableAttribute by calculation the post-obit line in your app'south AssemblyInfo.cpp file:

                      [associates:Organization::Diagnostics::DebuggableAttribute(true, true)];                                  

    For more information, encounter DebuggableAttribute.

Use Just-In-Time debugging

This example walks you lot through Simply-In-Time debugging when an app throws an error.

  • Y'all must have Visual Studio installed to follow these steps. If you don't have Visual Studio, yous tin can download the gratuitous Visual Studio Community Edition.

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

For this example, you lot'll make a C# console app in Visual Studio that throws a NullReferenceException.

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

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

                      static void Main(string[] args) {     Console.WriteLine("we will at present throw a NullReferenceException");     throw new NullReferenceException("this is the exception thrown by the console app"); }                                  
  3. To build the solution, cull either the Debug (default) or Release configuration, so select Build > Rebuild Solution.

    Note

    • Cull Debug configuration for the full debugging experience.
    • If you select Release configuration, you must plow off Just My Code for this procedure to work. Under Tools > Options > Debugging, deselect Enable Just My Code.

    For more data virtually build configurations, run into Understanding build configurations.

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

    You 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 But-In-Fourth dimension 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.

    Under Bachelor Debuggers, select New instance of <your preferred Visual Studio version/edition>, if non already selected.

  6. Select OK.

    The ThrowsNullException project opens in a new instance 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.

You can start debugging at this point. If you were debugging a real app, you would need to detect out why the code is throwing the exception.

Caution

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

Troubleshoot Just-In-Time debugging

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

  • Windows Error Reporting could be taking over the fault treatment on your computer.

    To fix this issue, use Registry Editor to add a DWORD Value of Disabled, with Value data of 1, 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 Error Reporting

    For more information, see .WER settings.

  • A known Windows issue may be causing the Just-In-Fourth dimension debugger to fail.

    The ready is to add together a DWORD Value of Auto, with Value information of 1, to the following registry keys:

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

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

Yous might meet the post-obit fault messages during Merely-In-Fourth dimension 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 process running nether another user.

    To piece of work around this problem, in Visual Studio, open up Debug > Attach to Process (or press Ctrl + Alt + P), and find the process you desire to debug in the Available Processes list. If you practise non know the name of the procedure, notice the Procedure ID in the Visual Studio Just-In-Fourth dimension Debugger dialog. Select the procedure in the Available Processes listing, 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 brandish the Just-In-Time debugging dialog.

    To fix this trouble, log onto the machine.

  • Course non registered.

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

    To fix this trouble, employ the Visual Studio Installer to reinstall or repair your Visual Studio installation.

See also

  • Debugger security
  • First look at the debugger
  • Options, Debugging, Just-In-Time dialog box
  • Security Warning: Attaching to a process owned by an untrusted user tin can exist dangerous. If the following information looks suspicious or you are unsure, do not attach to this procedure