An access violation (also known as segmentation fault) is generally an attempt to access memory that the CPU cannot physically address. It is often caused when attempting to access a null reference or a reference to memory that has been freed.
Questions tagged [access-violation]
1564 questions
50
votes
2 answers
How to interpret this stack trace
I recently released a Windows phone 8 app.
The app sometimes seem to crash randomly but the problem is it crash without breaking and the only info I get is a message on output that tells me there were an Access violation without giving any…

Fabio Marcolini
- 2,315
- 2
- 24
- 30
40
votes
14 answers
Attempted to read or write protected memory
I've started seeing an AccessViolationException being thrown in my application a several different spots. It never occured on my development pc, our test server. It also only manifested itself on 1 of our 2 production servers. Because it only…

Jeremy
- 44,950
- 68
- 206
- 332
34
votes
3 answers
Gracefully handling corrupted state exceptions
Related to this question, I would like to force CLR to let my .NET 4.5.2 app catch Corrupted State Exceptions, for the sole purpose of logging them and then terminating the application. What's the correct way to do this, if I have catch (Exception…

Lou
- 4,244
- 3
- 33
- 72
31
votes
5 answers
Finding the cause of System.AccessViolationException
Our application experiences the odd fatal System.AccessViolationException. We see these as we've configured the AppDomain.CurrentDomain.UnhandledException event to log the exception.
Exception: System.AccessViolationException: Attempted to read or…

chillitom
- 24,888
- 17
- 83
- 118
31
votes
3 answers
0xC0000005: Access violation reading location 0x00000000
I'm having a very strange issue with a space invaders game I'm working on. Basically I get an access violation error:
Unhandled exception at 0x5edad442 (msvcr100d.dll) in
SpaceInvaders.exe: 0xC0000005: Access violation reading location
…

Milk
- 647
- 1
- 6
- 18
28
votes
2 answers
Why AccessViolationException cannot be caught by .NET4.0
It is really interesting that the following C# code will crash on .NET4.0 but work fine on .NET2.0.
C# code
class Program
{
static void Main(string[] args)
{
try
{
ExceptionTest();
…

Miles Chen
- 793
- 1
- 10
- 20
26
votes
5 answers
Why doesn't *(int*)0=0 cause an access violation?
For educational purposes, I'm writing a set of methods that cause runtime exceptions in C# to understand what all the exceptions are and what causes them. Right now, I'm tinkering with programs that cause an AccessViolationException.
The most…

Peter Olson
- 139,199
- 49
- 202
- 242
24
votes
5 answers
Why can't I return a char* string from C++ to C# in a Release build?
I'm attempting to call the following trivial C function from C#:
SIMPLEDLL_API const char* ReturnString()
{
return "Returning a static string!";
}
With the following P/Invoke declaration (with or without the return attribute, it makes no…

Qwertie
- 16,354
- 20
- 105
- 148
23
votes
3 answers
Access violation in code that is not mine
I'm not sure how to go about debugging this. I have a C# program consisting entirely of managed code, running in .NET 4.5. After running it for a while, at some seemingly random time, I get a an error "An unhandled exception of type…

Mike
- 954
- 6
- 10
22
votes
4 answers
Debugging Access Violation errors?
What tips can you share to help locate and fix access violations when writing applications in Delphi?
I believe access violations are usually caused by trying to access something in memory that has not yet been created such as an Object etc?
I find…
user741875
22
votes
2 answers
Visual C++ Unmanaged Code: Use /EHa or /EHsc for C++ exceptions?
If I'm creating a new project in unmanaged C++, Visual Studio 2008 or greater, which exception handling model do I want to go with?
I understand that /EHa option results in less efficient code, and also catches SEH exceptions, right?
So I have been…

Fauxcuss
- 474
- 2
- 6
- 13
21
votes
3 answers
Is it OK to access past the size of a structure via member address, with enough space allocated?
Specifically, is the following code, the line below the marker, OK?
struct S{
int a;
};
#include
int main(){
struct S *p;
p = malloc(sizeof(struct S) + 1000);
// This line:
*(&(p->a) + 1) = 0;
}
People have argued…

iBug
- 35,554
- 7
- 89
- 134
20
votes
2 answers
Exception Error c0000005 in VC++
Am working on VC++ Console Application.
This application sends a file from Appdata\Roaming folder for a period of time.
What happens is am getting this Crash error :
Problem signature:
Problem Event Name: APPCRASH
Application Name: …

user1465461
- 397
- 2
- 6
- 17
18
votes
2 answers
How to test handling of AccessViolationException
I need to write a test which verifies that my code can handle an AccessViolationException (or any other WIN32 Corrupted State Exception - CSE), which occours in an unsafe context, typically by calling a 3rd party lib.
This should all be done using…

Christian Mikkelsen
- 1,661
- 2
- 19
- 44
17
votes
1 answer
Access Violation in function CreateProcess in Delphi 2009
In my program I've the following code:
//Code
if not CreateProcess(nil, NonConstCmd, nil, nil, True, NORMAL_PRIORITY_CLASS or
CREATE_NEW_PROCESS_GROUP, nil, PCh, SI, P) then
//Code
And I keep getting Access violation error.
By the way, in…

vralex
- 251
- 3
- 7