The DebuggerStepThrough attribute is another of the debugger attributes that should be used carefully and only on well-tested code. Like the DebuggerHidden attribute, when the DebuggerStepThrough attribute is applied to a piece of code, that code is stepped over during debugging.

Similar to the DebuggerHidden attribute, breakpoints cannot be set within a block of code marked with the DebuggerStepThrough attribute. However, within the call stack the attributed code will be marked as external code. For example, consider the following code snippet where the DebuggerStepThrough attribute has been set on HiddenMethod:

private void ClickHandler(object sender, EventArgs e)
{
   HiddenMethod();
}

[DebuggerStepThrough()]
public void HiddenMethod()
{
   Console.WriteLine("Can't set a breakpoint here");
   NotSoHiddenMethod();
}

public void NotSoHiddenMethod()
{
   Console.WriteLine("Can set a breakpoint here!");
}

If you run this code with a breakpoint set in NotSoHiddenMethod, the call stack will appear as shown below:

Call stack showing the effect of the DebuggerStepThrough attribute

Visual Studio 2008 supports the Just My Code option, configurable from the Debugging node in the Options dialog (select Tools > Options). Unchecking this option makes all code contained within your application appear in the call stack, as shown below. This includes designer and other generated code that you might not want to debug. Once this option is unchecked, breakpoints can also be set in blocks of code marked with this attribute.

Call stack showing the effect of the DebuggerStepThrough attribute combined with the Just My Code setting

DebuggerStepThrough is very useful when working with code that calls a lot of properties, for example, if you are calling a method that passes in a large number of properties as parameters. If you add the DebuggerStepThrough attribute to all the properties, and then you won’t step into all of the properties when debugging the method call.