Is there an attribute I can use on a method so that when stepping through some code in Debug mode the Debugger stays on the outside of the method?
4 Answers
[DebuggerStepThrough]
(docs)

- 7,563
- 8
- 55
- 82

- 14,340
- 7
- 51
- 50
-
Thanks. I'm such a "Logger", the debugger skills are getting rusty. – BuddyJoe Jan 15 '09 at 01:17
-
What about an attribute for a property? [DebuggerStepThrough] is only valid on Classes, Structs, Constructors and Methods – Marchy Sep 08 '09 at 21:31
-
Is there an inverse of this? I have a partial class linked to a generated partial class which has the [DebuggerStepThrough] attribute. I want to be able to step through my code without having to change VS's debugger properties. – Mike G Feb 14 '14 at 13:42
-
3Make sure to add `using System.Diagnostics;` – Chad Dec 28 '16 at 15:48
-
1This doesn't step over the whole method (as asked in the question), it skips THROUGH it - so the debugger stops at the first method called within. So [DebuggerStepThrough] is only useful for very small methods which make no other calls. – Jun 14 '17 at 08:54
It's written <DebuggerStepThrough>
in VB.NET.
To use it just put on top of the method like :
<DebuggerStepThrough>
Private Sub form_Paint(sender As Object, e As PaintEventArgs) Handles form.Paint
' Picasso
End Sub

- 2,080
- 2
- 19
- 44

- 666
- 1
- 18
- 31
Answering in general (and to @Marchy in particular, even if 14 years after the fact).
A word of warning: Verbose code ahead. I don't like to have VB's Imports
or C# using
in my code because most of the example code I stumble upon almost invariably omit these declarations and just show the code, with no clue to the reader as from where the objects/classes/methods invoked come out.
In C#, you flag classes and functions as "debugger step thru" as follows:
[System.Diagnostics.DebuggerStepThrough]
class someClass {
...
}
[System.Diagnostics.DebuggerStepThrough]
void someMethod (args...){
...
}
In VB, on the other hand, the syntax is almost the same; just use angle-brackets whenever you see C#'s square-brackets:
<System.Diagnostics.DebuggerStepThrough>
Friend Class someClass
...
End Class
<System.Diagnostics.DebuggerStepThrough>
Private Sub someMethod (args...)
...
End Sub
But what about properties, @Marchy says? These kick you in the face with an error* if you add the attribute to the property declaration itself. The solution is to add the attribute to the Getter/Setter themselves instead, as it affects code in contrast to declarations. In VB:
Public Property propertyName
<System.Diagnostics.DebuggerStepThrough>
Get
...
End Get
<System.Diagnostics.DebuggerStepThrough>
Set (args...)
...
End Set
End Property
Hope it helps.
*The error is: Attribute 'DebuggerStepThroughAttribute' cannot be applied to '{propertyName}' because the attribute is not valid on this declaration type.

- 111
- 1