Debugging Managed Code
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer

Debugging Managed Code

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

In This Section

Diagnostic Messages in the Output Window
Describes the Debug and Trace classes, with which you can write run-time messages (in Visual Basic and Visual C#) to the Output window. These classes include output methods that allow information output without breaking execution, information output with breaking execution, and information output with breaking execution if a specified condition fails.
Assertions in Managed Code
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 Trace and Debug methods, considerations in Debug and Release versions of code, side effects, assert arguments, customizing assert behavior, and configuration files.
Stop Statements in Visual Basic
Describes the Stop statement, which provides an alternative to setting a breakpoint. Also provided is example code and comparisons between the Stop statement and the End statement as well as between Stop and the Assert statement.
Walkthrough: Debugging a Windows Form
Gives step-by-step instructions for creating a Windows Form and debugging that form. A Windows Form, which creates a standard 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 Managed Extensions for C++ are generally similar.
Debugging the OnStart Method
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.)
Mixed-Mode Debugging
Discusses debugging mixed-mode applications (any application that combines native code with managed code). There are a few special considerations that are mentioned in this topic: property evaluation in mixed-mode applications, missing call stack information, and setting breakpoints on system components in mixed mode (this causes the common language runtime to break and hangs the debugger).
Error: Debugging isn't possible because a kernel debugger is enabled on the system
Describes an error message that occurs if you try to debug managed code on a machine running Windows NT, Windows 2000, or Windows XP that has been started in debug mode.

Related Sections

Tracing and Instrumenting Applications
Describes tracing, a way for you to monitor the execution of your application while it is running, and instrumenting, which places 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 Trace and Debug.
Describes a linker option that adds DebuggableAttribute to code written with Managed Extensions for C++. This attribute is needed to use debugging features such as attach with Managed Extensions for C++.
Debugging Windows Service Applications
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 Services Control Manager to start, stop, pause, and continue your service.
Scalability and Performance Testing
Provides links to information on monitoring performance thresholds, scalability, performance, testing for availability, testing for manageability, testing for reliability, testing for scalability, and testing for securability.
Debugging and Profiling
Discusses debugging .NET Framework applications and the configuration requirements.
Debugging Script and Web Applications
Describes common debugging problems and techniques you may encounter when debugging script and Web applications. Sections include debugging ASP.NET and ASP Web applications, debugging ATL Server Web applications, Visual Studio and the Windows Script Debugger, Web server debugging errors, and troubleshooting.
What's New in Debugging
Description of new debugging features added in this release of Visual Studio .NET.
Debugging Changes in Visual Basic .NET
Provides information, targeted to previous users of Visual Basic, on debugging changes in Visual Studio .NET.
Debugging Home Page
Provides links to the larger sections of the debugging documentation. Information includes what's new in the debugger, settings and preparation, breakpoints, handling exceptions, edit and continue, debugging managed code, debugging Visual C++ projects, debugging COM and ActiveX, debugging DLLs, debugging SQL, and the user interface references.
© 2015 Microsoft