views:

48

answers:

1

Look at the following program.

The comments show the order of execution when I use Visual Studio 2008, and start, and step through the program only hitting the F11 (Step Into) debugging hotkey. The first column is what I actually experience now, the second column is what I expected to happen.

Note that the method in the class marked with the DebuggerNonUserCode attribute is stepped into, whereas the one with DebuggerStepThrough isn't. I expected the debugger to step over both of these. This did not happen before. I've tagged a lot of my classes with this attribute, since I don't want to wade through all that noise when debugging new features in my class library, but now the debugger walks right into them as though the attribute isn't there.

Anyone experienced this? Have I messed up an option somewhere in Visual Studio?

using System;
using System.Diagnostics;

namespace ConsoleApplication3
{
    class Program
    {
        static void Main(string[] args)
        {                                   // 1             // 1
            new C1().Test();                // 2, 5          // 2
            new C2().Test();                // 6             // 3
        }                                   // 7             // 4
    }

    [DebuggerNonUserCode]
    public class C1
    {
        [DebuggerNonUserCode]
        public void Test()
        {                                   // 3
        }                                   // 4
    }

    [DebuggerStepThrough]
    public class C2
    {
        [DebuggerStepThrough]
        public void Test()
        {
        }
    }
}
A: 

The attribute DebuggerNonUserCode will not break on the method call when there is an exception. The code will break on the next catch in the stack.1

DebuggerNonUserCode

ChaosPandion
But note the documentation for this attribute: " This attribute suppresses the display of these adjunct types and members in the debugger window **and automatically steps through, rather than into**, designer provided code." Visual Studio does not step through now, it steps into.
Lasse V. Karlsen