Congratulations to RS 4 picking up a subtle bug in my code.

I don't think this is build 748 specific. I was trawling through some code I've had running in production for a while and occasionally a runtime error was being logged which was odd but something I could ignore. I loaded the project and noticed the once green square was now yellow. I thought I'd clean up the code and I noticed one statement had a blue squiggly telling me the "Expression is always true".

Impossible I thought. The variable in the expression was assigned a few statements earlier. I looked at the code and sure enough, it was used in an "if" block that checked for null. Again, that was not right, surely? Once I looked at the detail of the 'offending' statement did I notice that I was not using the variable of the method I was calling on the previous line but that of a few lines previous.

Wow! That solved my bug and the reason why I was getting out of context trace messages in my runtime log file. Of course, these are the kind of subtle problems that VS can't solve on its own, but with RS it alerted me to a fundamental problem of my own creation. Thanks again RS team for an excellent diagnostic tool. :)

Please sign in to leave a comment.