Troubleshooting Exceptions: System.AccessViolationException
An AccessViolationException is thrown when there is an attempt to read from or write to protected memory.
An access violation occurs in unmanaged or unsafe code when it attempts to read or write to memory that has not been allocated, or to which it does not have access. 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.
In managed code, all references are either valid or null. Any operation that attempts to reference a null reference in verifiable code throws NullReferenceException.
Access violations in unmanaged code that bubble up to managed code are always wrapped in an AccessViolationException.