NullReferenceException Class
Collapse the table of content
Expand the table of content

NullReferenceException Class

The exception that is thrown when there is an attempt to dereference a null object reference.

For a list of all members of this type, see NullReferenceException Members.


[Visual Basic]
Public Class NullReferenceException
   Inherits SystemException
public class NullReferenceException : SystemException
public __gc class NullReferenceException : public SystemException
class NullReferenceException extends SystemException

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.


Note that applications throw the ArgumentNullException exception rather than the NullReferenceException exception discussed here.

The following Microsoft intermediate language (MSIL) instructions throw NullReferenceException:

  • callvirt
  • cpblk
  • cpobj
  • initblk
  • ldelem.<type>
  • ldelema
  • ldfld
  • ldflda
  • ldind.<type>
  • ldlen
  • stelem.<type>
  • stfld
  • stind.<type>
  • throw
  • unbox

NullReferenceException uses the HRESULT COR_E_NULLREFERENCE, which has the value 0x80004003.

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


Namespace: System

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

Assembly: Mscorlib (in Mscorlib.dll)

See Also

NullReferenceException Members | System Namespace | Exception | Handling and Throwing Exceptions

© 2015 Microsoft