I know this might seem impossible at first and it seemed that way to me at first as well, but recently I have seen exactly this kind of code throw a NullReferenceException
, so it is definitely possible.
Unfortunately, there are pretty much no results on Google that explain when code like foo == null
can throw a NRE, which can make it difficult to debug and understand why it happened. So in the interest of documenting the possible ways this seemingly bizarre occurrence could happen.
In what ways can this code foo == null
throw a NullReferenceException
?