Solucionando problemas de exceções: System. AccessViolationException

Um AccessViolationException é lançada quando houver uma tentativa de ler ou gravar em memória protegida.

Associated Tips

  • Make sure that the memory that you are attempting to access has been allocated.
    Automatic memory management is one of the services that the common language runtime provides. You may wish to move to managed code to take advantage of this service. For more information, see Gerenciamento automático de memória.

  • Make sure that the memory that you are attempting to access has not been corrupted.
    If several read or write operations have occurred through bad pointers, memory may be corrupted.

Remarks

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. Qualquer operação que tenta referenciar uma referência nula no código verificável lança NullReferenceException.

Uma violação de acesso ocorre em código gerenciado não seguro pode ser expresso como um NullReferenceException ou AccessViolationException, dependendo da plataforma.

Violações de acesso em código não gerenciado que vão para código gerenciado sempre são encapsuladas em um AccessViolationException.

Consulte também

Tarefas

Como: Use o Assistente de exceção

Conceitos

Memory Management: Examples

Gerenciamento automático de memória