Tuesday, August 31, 2010

Why Breakpoint does not hit in Visual Studio?


Sometimes while you try to debug a problem in Visual Studio, breakpoints might not hit, and that's annoying. I've prepared a check list that you can follow to make the breakpoints hit when you encounter such situation:
1. Make sure that the Solution/Project is in Debug Mode and not in Release mode. 

2. Set a break point at the first line of Page_Load() method within the target page (If you are working with an Asp.net application) and see if that break point hits. If yes, proceed from that break point one by one line by pressing F10 or F11(Where necessary) to make sure that, your all conditions are correctly met before executing your target line of code. 

3. Make sure that, your target code actually builds when you build your solution/project. To do that, go to Build->Configuration Manager and make sure the corresponding project is checked (In the rightmost column). 

4. Make sure that your code is actually getting executing when you hit a page URL in the browser. If you debug by running the application under IIS, then try to debug using Debug->Attach to process->w3wp.exe. Also make sure that, you are hitting the correct page in correct way that could in turn executes your target code. 

5.If your break point is within a class library code, make sure that, your web site has a "Project reference" to that library, instead of a "dll reference"

6. Sometimes, some installed software in your OS might not allow you to debug by pressing F10 or F11 in your keyboard. In this case, try to debug by clicking the Debug->Step Into or Debug->Step over in the Visual Studio. 

7. Try with a System.Diagnostics.Debugger.Break() to see whether the system actually breaks. 

8. If nothing works, try to Clean the solution (Right click on the project/web site in the Solution explorer->Clean), then Rebuild or perhaps close the solution and restart it before clean and rebuild. 

Happy debugging :)


Sean Bopheka said...

What worked for my ASP.NET project on vs2010 is: I ran my ASP.NET project which debugged in internet explorer 10 since it's my default web browser, on the ie10 browser; I unchecked File/Work offline. Try this solution, hope it works for all of you who are having the same problem.

Dustin Morrow said...

This is the right blog for anyone who wants to find out about this topic. You realize so much its almost hard to argue with you. You definitely put a new spin on a topic that's been written about for years.

Post a Comment