Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Avoid debug and callstack for a piece of code in c#

In Delphi the compiler directives {$d-} and {$l-} allow you to effectively avoid generation of debug and local variable information for a defined section of code.

In a practical matter that has the effect to "hide" the code from the debug view, it doesn't appear in the call stack and you don't step into it while debugging.

Is there any way to achieve the same result in c# using VS 2008?

Note: The reason is we have a stable framework which does not need to be debugged but tend to mess up with the call stack and with the standard debug flow.

like image 467
Jorge Córdoba Avatar asked Jan 21 '23 17:01

Jorge Córdoba


1 Answers

I use DebuggerNonUserCodeAttribute so that you by default do not break or step into the code; However, the benifit to this over DebuggerStepThrough is that you can go to the Options->Debugger->Just My Code setting and allow breaking/debugging of the code you marked. This helps significantly if you have issues. I typically use it on entire classes.

BTW, the call stack will automatically hide non-user code as marked with this attribute :) Of course you can simply right-click the call stack window and toggle "Show External Code" to hide/show the missing stack information.

like image 67
csharptest.net Avatar answered Jan 30 '23 11:01

csharptest.net