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 thats 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 doesnt even go thru every line like I would expect. Also when I step thru 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 tho 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 doesnt work.
Edit:
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
.
Edit 2:
I've deleted my PDB files and cleaned solution. Still nothing.
Your code indicates a "service", which could be running as a separate process. If that's the case you can have your assembly loaded, so breakpoints would be solid red circles but another copy of the assembly, running in a separate process is actually handling the requests.
You could try to add a
Thread.Sleep(5000)
inGetStuff
method and use Attach to ProcessVisual Studio > Tools > Attach To Process and see if breakpoints below that line gets hit.
This sounds like the pdb files are not updated in your test sandbox.
1) Ensure that you are in debug mode.
2) Can you try and include a deployment item for the pdb files explicitly?
3) If 1 and 2 fail , I have found that sometimes visual studio requires a restart :)
VS behaves exactly the way you described (not hitting the breakpoints, hitting the code you're not expecting to hit when stepping through) when it uses .pdb file which was generated using the source code somehow different from the code which is used upon debugging. I can't guarantee that this is your case, but I've observed such behaviour many times when I needed to step into the code which was supplied as a pre-built library which was generated against an older/different code with same filenames/symbols.
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
Some ideas.
Debugger.Break()
in your code instead of a breakpoint in VSHave 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.