VS2012 Breakpoints are not getting hit

50,063

Solution 1

It turns out this was related to Code Coverage being on.

Turning it off fixed the issue.

You can find out how to disable code coverage by following below link

Disable code coverage

Solution 2

Some ideas.

  1. Make sure it's a debug build and not release
  2. Turn off optimizations in your project properties if they are on
  3. Try inserting Debugger.Break() in your code instead of a breakpoint in VS
  4. Make sure breakpoints are enabled (Debug->Windows->Breakpoints toolbar), and breakpoint symbol should be solid
  5. Execute your application. Load Debug->Window->Modules window. Check your assembly to see if symbols are loaded. It may give a relevant status message if not.

Have you been adjusting the date on your computer at all? This can really screw up a build process. If so, delete all your obj/bin folders manually and recompile.

Solution 3

It could be beacuse you are only debugging 1 project not both Test and Core

You can set VS to debug mutiple projects at once, you can do this by right-click your solution > Properties > Common Properties > StartUp Project

Here you can set "Multiple Startup Projects" enter image description here

Just set both Core and Test to start. This may solve your issue.

Solution 4

I have a very specific scenario that resulted in the apparent issue of "Breakpoint not being hit".

Since no other answers here mentioned it, I will add mine in the chance that it will help someone who had the same issue.

The solution, in my case, was silly, and with as much LINQ as I use I should have figured this out sooner. When running a method that returns an IEnumerable, where the return statements contained within are actually yield return statements, then that method will not be executed when you call it.

It will actually be executed when you call another method from that IEnumerable object, such as ToList() or Count(). Only then will the method be executed and the breakpoint reached.

Solution 5

Just make sure that you have build your assembly with the debugger symbols.

This option has to be filled with "full":

Right-Click your project containing your code file with the break points not getting hit. Choose "Properties".

After project properties have been opened, choose "Build" tab. Watch out for the "Advanced..."-Buttom at the bottom of the tab page. (Within the "Output"-Group")

Click this button and choose "full" for the "Debug info" property. This should be a reason for breakpoints not getting hit. Visual studio uses the symbols saved in the pdb-files to find the exact position of the break point. If these files are not created, no breakpoints are hit. Maybe you disabled the creation of these files in order to tidy up your project file structure. This was a situation I recognized that I need these files.

Share:
50,063
RJP
Author by

RJP

Updated on July 12, 2022

Comments

  • RJP
    RJP almost 2 years

    I have a class that looks like this:

    public class MyService
    {
        private MyService(){}
        public static string GetStuff()
        {
            var stuffDid = new MyService();
            return stuffDid.DoStuff();
        }
        private string DoStuff()
        {
            //do stuff
        }
        //other private helpers
    
    }
    

    Obviously I left a lot out, but that's the general shell.

    Now, I have a unit test:

    [Test]
    public void MyTest()
    {
    
        var results = MyService.GetStuff();
    }
    

    I set breakpoints on my unit test, and I can see that results has data. However, I set breakpoints literally all over MyService and nothing gets hit unless I put them on a curly brace. Which I can't understand since results has data, my return statements in MyService should be getting hit, right?

    Am I missing something? Did I completely forgot the most basic rules of something? How come nothing in MyService gets hit? And if I manually step into it with F11, it just hops around and doesn't even go through every line like I would expect. Also when I step through manually I tend to hit certain code after I should have hit it originally. And any switch statements seem to default to whatever the first option is, even though the value being switched should CLEARLY enter a different case.

    I've even tried making MyService constructor public and taking away all static methods, and it still doesn't work.

    My Tests and 'Core' code are in the same solution, but different projects(Test and Core, respectively). Other tests don't have an issue hitting break points in Core, only this on particular test (the only test that is testing MyService).

    I've deleted my PDB files and cleaned solution. Still nothing.