DebuggerHidden vs DebuggerStepThrough - nice interview question

In C# (and VB.NET) we can use an attribute on a class or on a method, to instruct Visual Studio to step over the code, when debugging.


This is especially useful, when debugging a project that has AOP  (Aspect Oriented Programming) injected code - for example for logging - and you are not interested in debugging the AOP code.

Two attributes that are very similar are DebuggerHidden and DebuggerStepThrough.


Here is a comparison between them (I found the Microsoft documentation to be a little confusing)

DebuggerHidden attribute:

- can be set on methods
- CANNOT be set on a class
- the code you are stepping over, does not appear at all in the call stack.  As far as the Call Stack is concerned, it is as if the hidden code does not exist (it is hidden!)

DebuggerStepThrough attribute:

- can be set on methods
- CAN be set on a class
- the code you are stepping over, appears in the call stack as 'external code'
This at least gives some indication to the debugging developer, that some extra code is at work.

Comments