Debugging
After a few weeks of coding, you'll enter the inevitable task of debugging and
resolving defects in your code. For this stage in the software lifecycle to be
successful, you need to know how to debug and test your code, and how to
resolve errors. For more information about unit testing in general, see our
section on
Unit Test Plans. For optimizing
your application and testing it's performance under load, see the section on
Optimization.
Configuring the Debugging Environment
Configuring your debugging environment is straightforward using Visual
Studio.NET. Unlike classic ASP, which required opening up multiple IDEs such as
Visual Interdev and Visual Basic to debug your application, you can debug your
application from within a single Visual Studio.NET instance. Open your web
project. Notice in the Solution Explorer that one project name is bold. This is
the StartUp Project: the project that is first loaded when you enter debug
mode. Make sure your web application, and not a class library, is set as your
StartUp Project. Next, select an aspx page, right click, and select Set As
Start Page. This will be the page loaded when you enter debug mode. You also
want to verify that you are using the Debug build configuration. On the
toolbar, notice the dropdown that has options for Debug, Release, and
Configuration Manager. Be sure this is set to Debug, or your breakpoints will
not work.
Applying Debugging Code
Next, open a code-behind file, right click a line of code and select Insert
Breakpoint. Now select Debug->Start, or press F5. Visual Studio.NET will load
your web application and stop at your breakpoint. You can then select
Debug->Step Into (F11) or Debug->Step Over (F10) to go through your source code
line-by-line. Using the Locals window, you can see the values of all local
variables. The Watch window allows you to indicate a specific variable to
watch.