How Can I Debug an Access Violation?

This topic applies to:

Edition

Visual Basic

C#

C++

Web Developer

Express

Topic does not apply Topic does not apply

Native only

Topic does not apply

Standard

Topic does not apply Topic does not apply

Native only

Topic does not apply

Pro and Team

Topic does not apply Topic does not apply

Native only

Topic does not apply

Table legend:

Topic applies

Applies

Topic does not apply

Does not apply

Topic applies but command hidden by default

Command or commands hidden by default.

Problem Description

My program produces an access violation. How can I debug this?

Solution

Use the Call Stack window to work your way back up the call stack, looking for corrupted data being passed as a parameter to a function. If that fails, try setting a breakpoint at a point before the location where the access violation occurs. Check to see if data is good at that point. If so, try stepping your way toward the location where the access violation occurred. If you can identify a single action, such as a menu command that led to the access violation, you can try another technique: set a breakpoint between the action (in this example, the menu command) and the access violation. You can then look at the state of your program during the moments leading up to the access violation.

You can use a combination of these techniques to work forward and backward until you have isolated the location where the access violation occurred. For more information, see Using the Call Stack Window.

See Also

Concepts

Debugging Native Code FAQs

Other Resources

Debugging Native Code