Uncovering a bug in Attribute.GetHashCode
It started from a question on StackOverflow. The following code will return inconsistent value for the hashcode of the attribute: View the code on Gist. This will print the output: 1234567 0 0 We can see that the hashcode value changes between the first and second invocation. Even more interesting, commenting line 3 seems to fix the behavior and GetHashCode will always return 1234567. To understand what’s going on, we first need to look at the source code of the Attribute.GetHashCode method: View the code on Gist. In a nutshell, what it does is: Enumerate the fields of your attribute Find the first field thatRead More →