Debugging Managed Code

This section covers common debugging problems and techniques for managed applications, or applications written in languages that target the common language runtime, such as Visual Basic, C#, and C++. The techniques described here are high-level techniques. For more information, see Using the Debugger.

Describes the Debug and Trace classes, with which you can write run-time messages to the Output window. These classes include output methods that enable information output without breaking execution and information output that also breaks execution if a specified condition fails.

Describes assertions in managed code, which test conditions that you specify as arguments to Assert methods. In addition, this topic provides example code, information on using Debug and Trace class methods, considerations in Debug and Release versions of code, side effects, assert arguments, customizing assert behavior, and configuration files.

Describes the Stop statement, which provides an alternative to setting a breakpoint. Example code is also provided, along with comparisons between the Stop statement and the End statement, as well as between Stop and the Assert statement.

Gives step-by-step instructions for creating a Windows Form and debugging that form. A Windows Form, a standard component of a managed Windows application, is one of the most common managed applications. This walkthrough uses Visual C# and Visual Basic, but the techniques for creating a Windows form with C++ are generally similar.

Provides code examples to allow you to debug the OnStart method of a managed Windows service. To debug the OnStart method of a Windows service, you must add a few lines of code to simulate the service.

Find bugs faster and easier by recording your app's execution history with IntelliTrace. Step backward and forward through recorded events and calls to examine your app's state at key points in time. Debug your code without setting lots of breakpoints or restarting your app as frequently. Requires Visual Studio Ultimate.

Describes tracing, a way for you to monitor the execution of your application while it is running, and instrumenting, which involves placing trace statements at strategic locations in your code. This topic also provides links to an introduction to instrumentation and tracing, trace switches, trace listeners, tracing code in an application, adding trace statements to application code, and compiling conditionally with Debug and Trace.

Provides considerations for debugging Windows service applications, including setting up, attaching to the process, debugging the code in the service's OnStart method and the code in the Main method, setting breakpoints, and using the Services Control Manager to start, stop, pause, and continue your service.