mscorlib 2.0.0.0 4.0.0.0 System.SystemException System.Runtime.InteropServices.ComVisible(true)

An access violation occurs in unmanaged or unsafe code when the code attempts to read or write to memory that has not been allocated, or to which it does not have access. This usually occurs because a pointer has a bad value. Not all reads or writes through bad pointers lead to access violations, so an access violation usually indicates that several reads or writes have occurred through bad pointers, and that memory might be corrupted. Thus, access violations almost always indicate serious programming errors. An clearly identifies these serious errors.

In programs consisting entirely of verifiable managed code, all references are either valid or null, and access violations are impossible. An occurs only when verifiable managed code interacts with unmanaged code or with unsafe managed code.

Starting with the net_v40_long, exceptions thrown by the common language runtime are not handled by the catch statement in a structured exception handler if the exception occurs outside of the memory reserved by the common language runtime. To handle such an exception, you should apply the attribute to the method in which the exception is thrown. This change does not affect exceptions thrown by user code, which can continue to be caught by a catch statement. For code written for previous versions of the .NET Framework that you want to recompile and run without modification on the net_v40_long, you can add the <legacyCorruptedStateExceptionsPolicy> element to your app's configuration file. Note that you can also receive notification of the exceptions if you have defined a handler for the or event.

## Version Information

This exception is thrown in the .NET Framework 2.0 and later versions. In earlier versions of the .NET Framework, an access violation in unmanaged code or unsafe managed code is represented by a in managed code. A is also thrown when a null reference is dereferenced in verifiable managed code, an occurrence that does not involve data corruption, and there is no way to distinguish between the two situations in versions 1.0 or 1.1.

Administrators can allow selected applications to revert to the behavior of the .NET Framework version 1.1. Place the following line in the <runtime> Element section of the configuration file for the application:

`<legacyNullReferenceExceptionPolicy enabled = "1"/>`

The exception that is thrown when there is an attempt to read or write protected memory.

- Constructor
  2.0.0.0
  4.0.0.0

  This constructor initializes the property of the new instance to a system-supplied message that describes the error, such as "Attempted to read or write protected memory. This is often an indication that other memory has been corrupted." This message takes into account the current system culture.

  The following table shows the initial property values for an instance of .

  Property

  Value

  null.

  The localized error message string.

  Initializes a new instance of the class with a system-supplied message that describes the error.

- Constructor
  2.0.0.0
  4.0.0.0

  The following table shows the initial property values for an instance of .

  Property

  Value

  null.

  The error message string specified in .

  Initializes a new instance of the class with a specified message that describes the error.

  The message that describes the exception. The caller of this constructor is required to ensure that this string has been localized for the current system culture.
- Constructor
  2.0.0.0
  4.0.0.0

  This constructor is called during deserialization to reconstitute the exception object transmitted over a stream. For more information, see XML and Soap Serialization.

  Initializes a new instance of the class with serialized data.

  The that holds the serialized object data.
  The that contains contextual information about the source or destination.
- Constructor
  2.0.0.0
  4.0.0.0

  An exception that is thrown as a direct result of a previous exception should include a reference to the previous exception in the property. The property returns the same value that is passed into the constructor, or null if the property does not supply the inner exception value to the constructor.

  The following table shows the initial property values for an instance of .

  Property

  Value

  null.

  The error message string specified in .

  Initializes a new instance of the class with a specified error message and a reference to the inner exception that is the cause of this exception.

  The message that describes the exception. The caller of this constructor is required to ensure that this string has been localized for the current system culture.
  The exception that is the cause of the current exception. If the parameter is not null, the current exception is raised in a catch block that handles the inner exception.