ArgumentNullException is the little, more specialized, brother of ArgumentException and is used to signal an unexpected null reference supplied for a parameter. Again, it pinpoints a missing null check in your code and should be treated seriously. Ask yourself how the null reference got to that very place in the code to begin with.

Extinguish the evil null reference as close to its root as possible (for example, an entry point to the component you’re developing). And the way to do it is by throwing exactly this exception. Constructors typically used for this purpose include the following:

public ArgumentNullException(string paramName);public ArgumentNullException(string paramName, string message); ...

Get C# 5.0 Unleashed now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.