Skip to content

Making an Image Easier to Debug

ElektroKill edited this page Jul 19, 2022 · 2 revisions

When attaching to a random .NET process, it's most likely already optimized. This will worsen the debugging experience because the debugger can't read all locals or evaluate expressions or call methods. If possible, you should always let the dnSpy debugger start the process. If the process is started by the dnSpy debugger, these additional steps are not necessary.

If you must attach to the process and the process is running on the .NET Framework, Microsoft recommends creating an INI file.

If your DLL is called something.dll, then create a something.ini file in the same folder with the following contents:

[.NET Framework Debugging Control]
GenerateTrackingInfo=1
AllowOptimize=0

NOTE: Make sure you save the file without a UTF8 BOM!

Note that you have to do this to every EXE/DLL you wish to debug and see all locals, it's not enough to do this to only the main exe.

If your process is running under .NET Core or .NET 5 and higher, the INI file will not work. In order to disable JIT optimizations on those runtimes please set the COMPlus_JITMinOpts environment variable to 1.

Setting environment variables COMPlus_ZapDisable to 1 and COMPlus_ReadyToRun to 0 can also be used to disable loading native images.

Clone this wiki locally