Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can DebuggerStepThrough be inherited into the automatically generated IEnumerable implementation?

The DebuggerStepThrough attribute allows you to skip breaking into certain methods/classes/properties.

In DebuggerStepThrough being ignored it is clarified that the c# compiler does not inherit this attribute into the compiler generated IEnumerable<T> implementation.

A trivial example of such a failure is:

static void Main(string[] args)
{
    var a = SkipMe().ToList();
}

[System.Diagnostics.DebuggerStepThrough]
static IEnumerable<int> SkipMe()
{
    // comment out line below and the throw will be stepped over.
    yield return 1;
    throw new Exception();
}

Is there a way to get the C# compiler to add the DebuggerStepThrough attribute to the auto generated type?

Is there a way to get visual studio to skip debugging into any types with the [CompilerGenerated] attribute?

--

Addendum: some illustrative screenshots

Result after pressing F5

screen 1

screen 2

Visual Studio Version:

snip 3

Our missing attribute:

the missing attribute

like image 222
Sam Saffron Avatar asked Jan 06 '12 00:01

Sam Saffron


1 Answers

I don't think there is a way to achieve the effect you're looking for.

  • There is no way to make the C# compiler copy this attribute into the generate state machine method.
  • You can't get around this by adding DebuggerStepThrough to the class containing the iterator method. The debugger only looks at the immediate parent type not the types containing a nested type.

The only real way I can think of to achieve this is to put all of the code you don't want to debug into in a separate DLL. Then don't load the PDB for that particular DLL.

like image 72
JaredPar Avatar answered Oct 24 '22 18:10

JaredPar