Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
If you're trying to debug code, it's easier when that code is NOT optimized. When code is optimized, the compiler and runtime make changes to the emitted CPU code so it runs faster, but has a less direct mapping to original source code. If the mapping is less direct, debuggers are frequently unable to tell you the value of local variables, and code stepping and breakpoints might not work as you expect.
Note
For more information on JIT (Just-In-Time) debugging, see Debug using the Just-In-Time Debugger in Visual Studio.
How optimizations work in .NET
Normally the Release build configuration creates optimized code and the Debug build configuration doesn't. The Optimize MSBuild property controls whether the compiler is told to optimize code.
In the .NET ecosystem, code is turned from source to CPU instructions in a two-step process: first, the C# compiler converts the text you type to an intermediate binary form called MSIL and writes the MSIL out to .dll files. Later, the .NET Runtime converts this MSIL to CPU instructions. Both steps can optimize to some degree, but the second step performed by the .NET Runtime performs the more significant optimizations.
The 'Suppress JIT optimization on module load (Managed only)' option
The debugger exposes an option that controls what happens when a DLL compiled with optimizations enabled loads inside of the target process. If this option is unchecked (the default state), then when the .NET Runtime compiles the MSIL code into CPU code, it leaves the optimizations enabled. If the option is checked, then the debugger requests that optimizations be disabled.
You can configure the Suppress JIT optimization on module load (Managed only) option in the Tools > Options pane, in the All Settings > General > Debugging section:
You can configure the Suppress JIT optimization on module load (Managed only) option in the Tools > Options dialog, in the General > Debugging section:

When should you check the 'Suppress JIT optimization' option?
Check this option when you downloaded the DLLs from another source, such as a NuGet package, and you want to debug the code in this DLL. In order for suppression to work, you must also find the symbol (.pdb) file for this DLL.
If you're only interested in debugging the code you're building locally, it's best to leave this option unchecked, as, in some cases, enabling this option significantly slows debugging. There are two reasons for the slowdown:
- Optimized code runs faster. If you're turning off optimizations for lots of code, the performance impact can add up.
- If you have Just My Code enabled, the debugger doesn't even try to load symbols for DLLs that are optimized. Finding symbols can take a long time.
Limitations of the 'Suppress JIT optimization' option
There are two scenarios where enabling this option does NOT work:
- If you attach the debugger to an already running process, this option has no effect on modules already loaded at the time the debugger is attached.
This option has no effect on DLLs precompiled (or ngen'ed) to native code. However, you can disable usage of precompiled code by starting the process with the environment variable 'COMPlus_ReadyToRun' set to '0'. This approach tells the .NET Core runtime to disable the use of precompiled images, which forces the runtime to JIT compile framework code.
If you're targeting the .NET Framework, add the environment variable 'COMPlus_ZapDisable' and set it to '1'.
Set "COMPlus_ReadyToRun": "0" by adding it to each profile in the Properties\launchSettings.json file:
{ "iisSettings": { "windowsAuthentication": false, "anonymousAuthentication": true, "iisExpress": { "applicationUrl": "http://localhost:59694/", "sslPort": 44320 } }, "profiles": { "IIS Express": { "commandName": "IISExpress", "launchBrowser": true, "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development", "COMPlus_ReadyToRun": "0" } }, "HttpLoggingSample": { "commandName": "Project", "launchBrowser": true, "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development", "COMPlus_ReadyToRun": "0" }, "applicationUrl": "https://localhost:5001;http://localhost:5000" } } }