System.ArgumentNullException Class

The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method that does not accept it as a valid argument.

See Also: ArgumentNullException Members

Syntax

[System.Runtime.InteropServices.ComVisible(true)]
public class ArgumentNullException : ArgumentException

Remarks

ArgumentNullException is thrown when a method is invoked and at least one of the passed arguments is null but 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 arguments that are not null. For errors caused by arguments that are not null, see ArgumentOutOfRangeException.

ArgumentNullException uses the HRESULT E_POINTER, which has the value 0x80004003.

For a list of initial property values for an instance of ArgumentNullException, see the ArgumentNullException constructors.

Thread Safety

All public static members of this type are safe for multithreaded operations. No instance members are guaranteed to be thread safe.

Example

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.
Parameter name: value
at System.String.Join(String separator, String[] value)
at ArgumentNullTest.Main()

Requirements

Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0