Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
213 views
in Technique[技术] by (71.8m points)

c# - VS2012 Breakpoints are not getting hit

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.

question from:https://stackoverflow.com/questions/14025734/vs2012-breakpoints-are-not-getting-hit

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...