Using/abusing a conditional breakpoint to manipulate a value

88 views Asked by At

For a temporary workaround, I have to set User.ID to 0 in a certain line. My usual approach for similar cases is to set a breakpoint at the corresponding line and use the watch to manipulate the value:

User.ID = 0

In an attempt to streamline this by automatically setting the value, I came up with a conditional breakpoint with this condition:

Convert.ToBoolean(User.ID = 0)

Since this expression evaluates to false, the code execution does not stop and as a side effect User.ID would be set to 0. As it turns out, this side effect does not happen. I am sure that this is by design. The exact same code works as expected in the watch, though. My questions:

  • How does Visual Studio handle side effects in conditional breakpoints and is there maybe some official documentation for that?
  • Can Visual Studio be tricked to allow this side effect?
  • Is there an alternative way to reach the desired behaviour (i. e. setting a variable automatically at a certain point while debugging)?

Conditional Breakpoint

1

There are 1 answers

2
Tim Schmelter On BEST ANSWER

My question seems to be related: Why does the debugger's breakpoint condition allow an assignment-statement as bool-condition?

It seems that this bug(in my opinion the debugger should not allow side effects from a breakpoint condition) was fixed in VS2013.

You have to change the setting if you want that side-effect:

  • Tools + Options
  • Debugging
  • General --> "Use Managed Compatibility Mode" checkbox

Tick that and you should get the old behaviour. I'm on 2010 so i cannot test it. But i trust Hans Passant in this.