我不知道如何去调试这个。我有一个完全由.NET 4.5运行的托管代码组成的C#程序。运行一段时间后,在一些看似随机的时间,我得到一个错误“mscorlib.dll中发生'System.AccessViolationException'类型的未处理的异常”。因为我从Visual Studio(2012)上运行它,我点击“破发”和我看到下面的调用堆栈:不是我的代码中的访问冲突
mscorlib.dll!System.Threading._IOCompletionCallback.PerformIOCompletionCallback(uint errorCode, uint numBytes, System.Threading.NativeOverlapped* pOVERLAP) + 0x47 bytes
[Native to Managed Transition]
[email protected]() + 0xc bytes
[email protected]() + 0x4f bytes
[email protected]() + 0x2b bytes
[email protected]() + 0xf bytes
[email protected]() + 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()
[email protected]() + 0x14 bytes
[email protected]() + 0xc bytes
[email protected]() + 0xc bytes
[email protected]() + 0x1a bytes
我发现一个有趣的事情是,没有在调用堆栈是我的代码。
你会建议我使用什么策略来找到问题的路线?或者你是否看到类似这样的问题并有任何提示?
由于异常似乎没有包含我的代码,因此我不知道包含什么信息可以帮助回答问题,但问我是否还有其他内容。
由于误差可以IO相关(因为PerformIOCompletionCallback是在堆栈的顶部),这是典型的IO任务的列表,该应用程序执行:
- TcpListener.AcceptTcpClientAsync
- 的NetworkStream。写/的BeginRead/EndRead
- SqlCommand.BeginExecuteReader/EndExecuteReader
- StreamWriter.WriteLine
其他说明:
- 这似乎是大致重复的 - 我得到在同一个地方(PerformIOCompletionCallback)相同的错误,但必须等待不同长度的时间来得到它(以分钟为单位的顺序) 。
- 我不认为我可以制造一个可靠地突出显示问题的小程序。我的程序在遇到这个错误之前处理了数千个类似的IO操作。
编辑:基于由@Kevin的建议,即Mdnsnsp.dll是卓悦
,我卸载卓悦再次尝试。唯一的例外仍然存在,但调用堆栈更干净:
mscorlib.dll!System.Threading._IOCompletionCallback.PerformIOCompletionCallback(uint errorCode, uint numBytes, System.Threading.NativeOverlapped* pOVERLAP) + 0x47 bytes
[Native to Managed Transition]
[email protected]@12() + 0x12 bytes
[email protected]() + 0x27 bytes
[email protected]() + 0x1b bytes
我假设安装了网络流量的一些良性的钩子DLL卓悦的安装程序,但卸载它并没有解决这个问题。
编辑:
我已经暂时重新编码使用较慢的“安全”的等价物来消除,作为一个犯罪嫌疑人都是我unsafe
功能。现在应用程序中没有使用不安全开关编译程序集。问题依然存在。重申一下,我现在在这个应用程序中没有不安全的代码,没有本地代码,也没有P/Invoke调用(在用户代码中),但是我仍然遇到了如上所述的AccessViolationException
。
您是否恰好在boot.ini中启用了/ 3GB开关?我记得在我工作的系统上遇到过这样的奇怪错误。我得出结论,由于可用内存减少,因此处理I/O资源耗尽。 –
您是否在使用任何不安全的代码或P/Invoke? |这样的错误将适合GC移动一些本地代码仍然需要的缓冲区。 – CodesInChaos
托管代码正在调用的非托管代码可能会引发异常。 [启用非托管代码调试](http://msdn.microsoft.com/en-us/library/vstudio/tdw0c6sf%28v=vs.100%29.aspx),然后尝试调试您的程序。 – keyboardP