locked
"System.AccessViolationException" exception reason RRS feed

  • Question

  • Hi,

    I have s .Net application in which occosionally I receive following exception:

    "Attempted to read or write protected memory. This is often an indication that other memory is corrupt. Name:<application>.exe
    There are no context policies."

    I need to know why this exception is raised? 

    Thanks

    Monday, May 16, 2011 1:23 PM

Answers

  • This is a low-level exception that is raised whenever code tries to read or write to memory that the current application does not own or have the right to use. Usually a pointer is pointing wrong, or is not initialized with a proper value.

    If you use unmanaged code somewhere you would need to review it. COM objects could also raise this exception if not properly used. And in combination with multithreading things are likely to blow up more randomly.

    To begin somewhere I'd try to get a stack trace to locate where the Access Violation occurs. Since the error is not likely to have happened at the end of the trace (unless you're lucky) you then have to figure out what code could have corrupted the state before the error happened. This is the most tricky part. If the exceptions come often you could apply some trial and error.

    /Calle


    - Still confused, but on a higher level -
    • Marked as answer by eryang Friday, May 27, 2011 6:44 AM
    Monday, May 16, 2011 9:09 PM
  • You can have a look at MDA to help you dignosis the code issue. Enable the following MDAs to see whether you can find some traces about culprit.

    http://msdn.microsoft.com/en-us/library/ya4zeek2.aspx

    http://msdn.microsoft.com/en-us/library/w5b3680b.aspx

     

    About MDA, see this article for more info:

    http://blogs.msdn.com/b/jmstall/archive/2005/11/10/introducing-mdas.aspx


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    • Marked as answer by eryang Friday, May 27, 2011 6:44 AM
    Tuesday, May 17, 2011 6:15 AM

All replies

  • This is a low-level exception that is raised whenever code tries to read or write to memory that the current application does not own or have the right to use. Usually a pointer is pointing wrong, or is not initialized with a proper value.

    If you use unmanaged code somewhere you would need to review it. COM objects could also raise this exception if not properly used. And in combination with multithreading things are likely to blow up more randomly.

    To begin somewhere I'd try to get a stack trace to locate where the Access Violation occurs. Since the error is not likely to have happened at the end of the trace (unless you're lucky) you then have to figure out what code could have corrupted the state before the error happened. This is the most tricky part. If the exceptions come often you could apply some trial and error.

    /Calle


    - Still confused, but on a higher level -
    • Marked as answer by eryang Friday, May 27, 2011 6:44 AM
    Monday, May 16, 2011 9:09 PM
  • You can have a look at MDA to help you dignosis the code issue. Enable the following MDAs to see whether you can find some traces about culprit.

    http://msdn.microsoft.com/en-us/library/ya4zeek2.aspx

    http://msdn.microsoft.com/en-us/library/w5b3680b.aspx

     

    About MDA, see this article for more info:

    http://blogs.msdn.com/b/jmstall/archive/2005/11/10/introducing-mdas.aspx


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    • Marked as answer by eryang Friday, May 27, 2011 6:44 AM
    Tuesday, May 17, 2011 6:15 AM
  • Thanks for reply.

    I have to look for COM/Win32 Dll usage in my application. MDA is going to be useful mechanism.

    Wednesday, May 18, 2011 4:10 PM
  • I couldn't find "MDA" key at following path:

    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework

    Do I have to create new key with "MDA" keyname to enable MDA?

     

    Wednesday, May 18, 2011 4:39 PM
  • You can enable MDAs by adding the HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\MDA subkey (type REG_SZ, value 1) in the Windows registry.

     

    Before you edit the registry, you'd better export the keys in the registry that you plan to edit, or back up the whole registry. If a problem occurs, you can then follow the steps in the How to restore the registry section of this article to restore the registry to its previous state.

     


    Eric Yang [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, May 23, 2011 8:42 AM