ArgumentNullException

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 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);

The first constructor often ...

Get C# 4.0 Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.