Search code examples
c#.netdebug-build

C# - Is there really a need for debug build in .net


If the release version produces .pdb files and you can step into every line, put breakpoints etc then why ever bother to build a "debug" version of my components?

I'm using c# for my projects and i didn't have problem debugging release versions. In C++ i had problems debugging optimized code but in C# it works fine. I'm not talking about silly code blocks like if(false)...


Solution

  • One reason is attach vs. launch.

    If you launch a Retail process in .Net, the debugging is almost nearly as good as launching a Debug process. You will likely not notice any difference in your debugging experience.

    Attach is a completely different ball game. Both C# and VB are passed the /optimize+ flag for retail builds. This will embed the DebuggableAttribute at the assembly level without the DebuggingMode.DisableOptimizations flag. During a process launch, VS / CLR, will communicate to essentially ignore this fact and disable JIT optimizationss that impact debugging. During attach, no such item happens and the JIT/CLR will optimize to it's hearts content. I guarantee you, the debugging experience is much worse in this case.

    You can experiment with this in VS

    • Switch build to Release
    • CTRL+F5 to launch with no debugging
    • Attach to the process.