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 'System.AccessViolationException' occurred in mscorlib.dll". Since I'm running it from Visual Studio (2012) I click "break" and am presented with the following call stack:

mscorlib.dll!System.Threading._IOCompletionCallback.PerformIOCompletionCallback(uint errorCode, uint numBytes, System.Threading.NativeOverlapped* pOVERLAP) + 0x47 bytes    
[Native to Managed Transition]  
ntdll.dll!_NtRequestWaitReplyPort@12()  + 0xc bytes 
kernel32.dll!_ConsoleClientCallServer@16()  + 0x4f bytes    
kernel32.dll!_GetConsoleLangId@4()  + 0x2b bytes    
kernel32.dll!_SetTEBLangID@0()  + 0xf bytes 
KernelBase.dll!_GetModuleHandleForUnicodeString@4()  + 0x22 bytes   
mdnsNSP.dll!7177aa48()  
[Frames below may be incorrect and/or missing, no symbols loaded for mdnsNSP.dll]   
mdnsNSP.dll!71775b06()  
mdnsNSP.dll!71774ded()  
mdnsNSP.dll!71774e8c()  
bcryptprimitives.dll!746d1159()     
bcryptprimitives.dll!746d1137()     
ntdll.dll!_LdrpCallInitRoutine@16()  + 0x14 bytes   
ntdll.dll!_NtTestAlert@0()  + 0xc bytes 
ntdll.dll!_NtContinue@8()  + 0xc bytes  
ntdll.dll!_LdrInitializeThunk@8()  + 0x1a bytes 

An interesting thing I notice is that nothing in the call stack is my code.

What strategy would you advise I use to find the route of the problem? Or have you seen a problem similar to this and have any tips?

Since the exception doesn't seem to include my code, I don't know what information to include that would be helpful in answering the question, but ask me if there is anything else that I should include.

Since the error may be IO related (since PerformIOCompletionCallback is at the top of the stack), this is a list of typical IO tasks that this application performs:

  • TcpListener
Edit
Report