Valamas
Valamas

Reputation: 24749

Why is DebuggerStepThrough ignored on linq statements?

While stepping through my code, I am finding certain lines deep down that are ignoring the DebuggerStepThrough attribute. It appears to be for within linq statements.

Here is a similar SO: DebuggerStepThrough being ignored

The code being stepped through is in Debug mode. It is in the same solution as the ReflectionHelper method below. The project reference is via project and not a compile dll elsewhere, I.e., the same output bin/debug folder as the project. Nothing else unusual is happening that may suggest the assembly being used is a different one as would be noticed while doing code changes on both project sides.

So as I am stepping through using the F11, it steps into the code below.

I have the following in my public static class ReflectionHelper

[DebuggerStepThrough]
public static bool Exists(string propertyName, object srcObject)
{
    PropertyInfo propInfoSrcObj = srcObject.GetType().GetProperties()
        .FirstOrDefault(p => p.Name == propertyName); //-- Debugger stops here
    return (propInfoSrcObj != null);
}

enter image description here How can I avoid this code stepping through? My current work around is SHIFT+F11 to step out before resuming my debugging with F11.

Another example of where this is happening is this code.

string databaseNamePair = split.Find(f => f.StartsWith("Initial Catalog")); 

Upvotes: 3

Views: 424

Answers (1)

spender
spender

Reputation: 120488

Those Linq statements contain lambda expressions that are compiled to method calls. Thus, the attribute is not applied to these distinct methods.

I suppose you could turn the lambdas into full blown methods so that you could tag them with that attribute, but it's going to make for fugly code.

Upvotes: 2

Related Questions