The exception that is thrown when there is an attempt to read or write protected memory.
Assembly: mscorlib (in mscorlib.dll)
Thetype exposes the following members.
|AccessViolationException()||Initializes a new instance of the class with a system-supplied message that describes the error.|
|AccessViolationException(String)||Initializes a new instance of the class with a specified message that describes the error.|
|AccessViolationException(SerializationInfo, StreamingContext)||Initializes a new instance of the class with serialized data.|
|AccessViolationException(String, Exception)||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.|
|Data||Gets a collection of key/value pairs that provide additional user-defined information about the exception. (Inherited from Exception.)|
|HelpLink||Gets or sets a link to the help file associated with this exception. (Inherited from Exception.)|
|HResult||Gets or sets HRESULT, a coded numerical value that is assigned to a specific exception. (Inherited from Exception.)|
|InnerException||Gets the Exception instance that caused the current exception. (Inherited from Exception.)|
|Message||Gets a message that describes the current exception. (Inherited from Exception.)|
|Source||Gets or sets the name of the application or the object that causes the error. (Inherited from Exception.)|
|StackTrace||Gets a string representation of the immediate frames on the call stack. (Inherited from Exception.)|
|TargetSite||Gets the method that throws the current exception. (Inherited from Exception.)|
|Equals(Object)||Determines whether the specified object is equal to the current object. (Inherited from Object.)|
|Finalize||Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)|
|GetBaseException||When overridden in a derived class, returns the Exception that is the root cause of one or more subsequent exceptions. (Inherited from Exception.)|
|GetHashCode||Serves as the default hash function. (Inherited from Object.)|
|GetObjectData||When overridden in a derived class, sets the SerializationInfo with information about the exception. (Inherited from Exception.)|
|GetType||Gets the runtime type of the current instance. (Inherited from Exception.)|
|MemberwiseClone||Creates a shallow copy of the current Object. (Inherited from Object.)|
|ToString||Creates and returns a string representation of the current exception. (Inherited from Exception.)|
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 Framework 4, 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 HandleProcessCorruptedStateExceptionsAttribute 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 Framework 4, 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 AppDomain.FirstChanceException or AppDomain.UnhandledException event.
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 NullReferenceException in managed code. A NullReferenceException 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"/>