When Is True Not True?

When you look at true stored in the .Net framework. While playing with Pex I found out a interesting fact that the bool is a byte in the MSIL. Which means that a bool could be equal to anything on the byte range… Now this would require you to go out of your way and create unsafe code blocks to do this. Why you would do this… No ideas :) Its marked as a no-fix which is not surprising as I would not fix it either because as they say, if you know about this and you use it then you are on your own.

References:

  • The original Microsoft Connect feedback item (ID 455553) is no longer available — Microsoft Connect was shut down in 2018. Search for “Pex bool byte MSIL true not true” if you want to find archived discussions.
  • The original dotnetwiki.org post on Pex, enums, and booleans is no longer available. You may find a copy via the Wayback Machine.