Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hit Breakpoint When Caused by the Debugger

Is there a way to have breakpoints hit when the action is caused by the Visual Studio debugger? For example, let's say I have the following (I know you shouldn't do this, just using it for argument's sake):

public class Test
{
    int _X = -1;
    public int X { 
        get { return ++_X; } //Breakpoint here
        set { _X = value; } 
    }
}

And:

static void Main(string[] args)
{

        Test t = new Test();
        t.X = 1;  //Breakpoint here
        return;
}

If you pause at the breakpoint in Main, every time you "hover" the mouse pointer over "t.X" (assuming you have the following Debugging option enabled - "Enable property evaluation and other implicit function calls") or you evaluate the property in the "watch" window - it will increment the property but the breakpoint in the property's "get" accessor will not be hit. Re-asking the question in a more specific context - is there a way to hit the breakpoint in the property's "get" accessor when the evaluation is done by the debugger?

like image 215
dugas Avatar asked Dec 30 '25 00:12

dugas


1 Answers

After some research on this topic, I learned about FuncEval, and after reading lots of things about FuncEval I was led to the following article: Stop Mid Func Eval, Nested Break States by Mr. SteveJS. In the article he explained that starting in VS2005 you could hit a breakpoint caused by a FuncEval if the evaluation was done from the "Immediate Window" instead of the Watch or "Quick Watch" windows. So, in the above example, entering

?t.X

in the Immediate Window caused the breakpoint on the get accessor to be hit.

like image 68
dugas Avatar answered Jan 01 '26 13:01

dugas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!