“Just My Code” Debugging

You may 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. Starting from Visual Basic 2005, and then also in Visual Basic 2010, 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 2010. To disable it or enable it, you simply need to 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.

Figure 5.1 Enabling/disabling Just My Code debugging.

image

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.

Listing 5.2 Understanding Just My Code Behind the Scenes

image

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 it will not be debugged when Just My Code is on. Basically three attributes influence the debugger’s behavior in this feature. Table 5.1 shows the complete list.

Table 5.1 Just My Code Attributes

image

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.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.16.69.106