Leif
Leif

Reputation: 2170

Using/abusing a conditional breakpoint to manipulate a value

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:

Conditional Breakpoint

Upvotes: 2

Views: 100

Answers (1)

Tim Schmelter
Tim Schmelter

Reputation: 460340

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.

Upvotes: 1

Related Questions