I found an issue with the debugger and “Watch” functionality today that was quite odd and puzzled me for a short while until I noticed the problem. I was attempting to compare two values stored in hash tables. The reason it wasn’t working was that I was forgetting to cast them to strings, so the program was comparing object references. The code went something like this.
If (dataValue[“SomeKey”] != otherData[“AnotherKey”])
Do something horrific.
So the code should trigger when the two items arn’t equal. Unfortunately it was triggering on code that was equal as well (the solution is to add “as string” after each dataValue – or your own preferred method of casting.)
The real trouble was however that when I copied that boolean function into my watch and debugged through it, the watch evaluates it as true! It would appear that the watch evaluates by doing an automatic convert whilst the program doesn’t, thus giving completely different values and confusing the hell out of me as I tried to solve the problem.
I guess it pays to remember when we’re hunting bugs that they can exist in our tools as well as our code.