Tips for dealing with missed breakpoints in Visual Studio

I’ve been doing a great deal of work with Visual Studio 2012 and Sitecore lately. Our largest solution contains nearly twenty projects with five web projects, and this one in particular suffers from “lost” or missed breakpoints during debugging. Seeing the empty red circle can be very frustrating on a tight deadline. Following are some tips that may help, with a nod to Stack Overflow.

  • Make sure that your project(s) are in debug mode. You can easily check this by right-clicking the solution and selecting Properties – Configuration Properties – Configuration.
  • Turn off optimizations in project properties, in the “Build” section.
  • Check project references, to make sure you are getting the latest built versions of assemblies. For intra-solution references, prefer to make references to other projects’ output instead of browsing to files.
  • Make sure that you are debugging all projects containing your breakpoints. Everyone is familiar with the “Set as Startup Project” option available when right-clicking a project within Visual Studio, but you can also set multiple projects to be debugged.
  • In Options – Debugging – General, ensure that "Enable Just My Code" is deselected.
  • While debugging, choose menu item Debug – Windows – Modules. For each module/assembly containing a skipped breakpoint which is listed as "Skipped loading symbols", right-click and select "Load symbols".
  • Get a clean build and set of debug symbols: Manually kill w3wp.exe or other process hosting your code, delete /obj/ folders, delete build assemblies and .pdb files, add or delete a meaningless character from a source file in each debugged project, use “Build – Clean Solution” and/or “Build – Clean [project name]”, and then rebuild.
  • Check “Debug – Windows – Breakpoints” to make sure that your breakpoints are recognized (they should be listed, checked, and filled with red).
  • Restart Visual Studio.
  • Make sure you are attaching to the correct process. For web projects I generally select project properties, select the “Web” side tab, and select “Use Local IIS Web server”, then attach to w3wp.exe .
  • If all else fails, insert System.Diagnostics.Debugger.Break() in your code, do a clean build and reattach. This sometimes seems to reset the debugger when it gets hinky, to the point that it will start recognizing breakpoints added through Visual Studio again. You can then delete the line of code, rebuild and reattach.