You might remember from Chapter 2 and Chapter 3, “The Anatomy of a Visual Basic Project,” that every time you create a Visual Basic application the IDE generates some background code. Moreover, your code often invokes system code that you do not necessarily need to investigate. In Visual Basic the IDE offers the capability of debugging just your own code, excluding system and auto-generated code. This feature is also known as Just My Code debugging. This is useful because you can focus on your code. Just My Code is enabled by default in Visual Studio 2015. To disable it or enable it, open the Options window, select the Debugging node on the left, and then flag or unflag the Enable Just My Code (Managed Only) check box, as shown in Figure 5.1.
Behind the scenes, Just My Code adds (or removes) some .NET attributes to auto-generated code that can influence the debugger behavior. To see a simple example, open or create a project and then click the Show All Files button in Solution Explorer. After doing this, go to the Settings.designer.vb code file. Listing 5.2 shows the content of the My
namespace definition inside the file.
Namespace My
<Global.Microsoft.VisualBasic.HideModuleNameAttribute(), _
Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
Global.System.Runtime.CompilerServices.CompilerGeneratedAttribute()> _
Friend Module MySettingsProperty
<Global.System.ComponentModel.
Design.HelpKeywordAttribute("My.Settings")> _
Friend ReadOnly Property Settings() As
Global.DebuggingFeatures.My.MySettings
Get
Return Global.DebuggingFeatures.My.MySettings.Default
End Get
End Property
End Module
End Namespace
You can notice that the module MySettingsProperty
is decorated with a particular attribute named System.Diagnostics.DebuggerNonUserCodeAttribute
. This attribute indicates to the debugger that the code is not your code (user code) and that it will not be debugged when Just My Code is on. Three attributes influence the debugger’s behavior in this feature. Table 5.1 shows the complete list.
Of course, you can use attributes of your own so that you can influence the behavior of the debugger when Just My Code is disabled.
18.118.23.147