This was a pain to debug. Basically, for reasons I'm not going to get into, we have a field in one of our classes that is not encapsulated. At some point, a bug was introduced (by me) where this field was modified essentially inside of another property (let's call it Name).
What made this confusing to debug was the fact that we provide a ToString() implementation that accesses both properties. If you put a breakpoint in Name, it won't get hit when it's called inside ToString(), which is called to display the value of the class in the Locals window and elsewhere.
Check out this screenshot below:
- CultureInfo.CurrentCulture.LCID is 1099 (Kannada, India)
- I'm setting NoSnappers.Lcid to 1041 (Japanese, Japan)
- Now look at the state of the program in the Locals window right after 1041 was assigned to this.info.Lcid
The fix was ridiculously simple (remove the line in Name that changes the Lcid), yet I spent a while reading about various possible reasons why setting a field of a struct could possibly fail. It just hasn't occurred to me that the field WAS in fact getting set, and then reset back to its original value somewhere else.
