Note that there are some explanatory texts on larger screens.

plurals
  1. POAccess violation in code that is not mine
    primarykey
    data
    text
    <p>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:</p> <pre><code>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 </code></pre> <p>An interesting thing I notice is that nothing in the call stack is my code. </p> <p>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?</p> <p>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. </p> <p>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:</p> <ul> <li>TcpListener.AcceptTcpClientAsync </li> <li>NetworkStream.Write/BeginRead/EndRead</li> <li>SqlCommand.BeginExecuteReader/EndExecuteReader</li> <li>StreamWriter.WriteLine</li> </ul> <p>Other notes:</p> <ul> <li>It seems to be roughly repeatable - I get the same error in the same place (PerformIOCompletionCallback), but have to wait a different length of time to get it (in the order of minutes). </li> <li>I don't think I can manufacture a small program that reliably highlights the problem. My program handles many thousands of similar IO operations before it hits this error.</li> </ul> <p><strong>Edit:</strong></p> <p>Based on the suggestion by @Kevin that Mdnsnsp.dll is from Bonjour, I uninstalled Bonjour and tried again. The exception persists, but the call stack is much cleaner:</p> <pre><code>mscorlib.dll!System.Threading._IOCompletionCallback.PerformIOCompletionCallback(uint errorCode, uint numBytes, System.Threading.NativeOverlapped* pOVERLAP) + 0x47 bytes [Native to Managed Transition] kernel32.dll!@BaseThreadInitThunk@12() + 0x12 bytes ntdll.dll!___RtlUserThreadStart@8() + 0x27 bytes ntdll.dll!__RtlUserThreadStart@8() + 0x1b bytes </code></pre> <p>I'm assuming the Bonjour installer installed some benign hook DLL for network traffic, but uninstalling it did not fix the problem.</p> <p><strong>Edit:</strong></p> <p>I have temporarily re-coded all my <code>unsafe</code> functions using slower "safe" equivalents to eliminate that as a suspect. Now none of the assemblies in the application are compiled using unsafe switch. The problem still persists. To reiterate, I now have no unsafe code, no native code and no P/Invoke calls (in user code) in this application, but I am still experiencing the <code>AccessViolationException</code> as described above.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload