Share via


Troubleshooting common breakpoint problems in the Visual Studio debugger (Part I)

On the Visual Studio debugger team, one of the areas where we regularly receive feedback is when breakpoints don't work. Furthermore, some of the error messages that the debugger displays when a breakpoint fails are generic so it might be hard to diagnose why a breakpoint doesn't work correctly (we're working to improve these error messages). In this blog post and subsequent posts, I'm going to cover the most common reasons why breakpoints don't work in the Visual Studio debugger and provide potential workarounds.

Problem

When trying to set a breakpoint in a C# or VB method, you see the following error message:

The common language runtime was unable to set the breakpoint.

Description

This error occurs because the application that you are debugging is optimized and the method where you are trying to set the breakpoint has been optimized away and hence, doesn't exist in the running application. This typically happens if your project configuration is set to Release mode which enables the compiler setting to optimize code, as shown below. One way to fix this problem is to set the project configuration to Debug which disables optimizations.

Project Properties

Habib Heydarian.