This behavior is so bizarre that I don’t even know how best to ask the question.
Given the following C# code snippet:
public class Foo { private bool _value = true; // ... protected void Method() { _value = true; if(!_value) { throw new Exception('What the...?!?!'); } } }
Attaching the Visual Studio debugger to an application executing a version of this code and stepping through the execution of Method() (using step into or step over), the if block is evaluated and the exception is thrown. Setting a watch on the _value variable, I can see that the value of _value is false at the beginning of the method and does not change as I step over/into the assignment statement. More interestingly, the exception is not thrown if I Continue execution (F5), though things still aren’t working correctly.
I came across this when trying to figure out why NUnit test cases were working when run using ReSharper from within visual studio, but fail when run within the the NUnit GUI. I attached the debugger to the NUnit GUI, set some breakpoints on the tests that were unexpectedly failing, found places where variables weren’t being set properly which should be set based on the above-mentioned _value variable which is somewhat of a flag indicating whether stuff is dirty or not), and thus noticed the strange behavior where _value wasn’t changing (the exception throwing thing was added later and verifies I was using the right compiled assemblies!).
So, how about it? What could possibly explain the above-mentioned behavior?
Since the exception isn’t actually thrown in some scenario’s I think this is a case of the debugger looking at the wrong source or wrong version.