Printer Friendly Version      Send     
Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
Previous Versions
.NET Framework 1.1
.NET Framework
Reference
System
This page is specific to
Microsoft Visual Studio 2003/.NET Framework 1.1

Other versions are also available for the following:
.NET Framework Class Library
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.

System.Object
   System.Exception
      System.SystemException
         System.NullReferenceException

[Visual Basic]
<Serializable>
Public Class NullReferenceException
   Inherits SystemException
[C#]
[Serializable]
public class NullReferenceException : SystemException
[C++]
[Serializable]
public __gc class NullReferenceException : public SystemException
[JScript]
public
   Serializable
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.

Remarks

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.

Requirements

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

© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker