See Also: ArgumentNullException Members
ArgumentNullException is thrown when a method is invoked and at least one of the passed arguments is null and should never be null .
ArgumentNullException behaves identically to ArgumentException. It is provided so that application code can differentiate between exceptions caused by null arguments and exceptions caused by non-null arguments. For errors caused by non-null arguments, see ArgumentOutOfRangeException .
The following example demonstrates an error that causes the string class to throw a ArgumentNullException exception.
C# Example
using System;
class ArgumentNullTest {
public static void Main() {
String[] s = null;
String sep = " ";
try {
String j = String.Join(sep,s);
}
catch (ArgumentNullException e) {
Console.WriteLine("Error: {0}",e);
}
}
}
The output is
Error: System.ArgumentNullException: Value cannot be null.