调试winform崩溃 – C#

System.AccessViolationException was unhandled Message=Attempted to read or write protected memory. This is often an indication that other memory is corrupt. Source=System.Windows.Forms StackTrace: at System.Windows.Forms.UnsafeNativeMethods.PeekMessage(MSG& msg, HandleRef hwnd, Int32 msgMin, Int32 msgMax, Int32 remove) at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData) at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context) at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context) at System.Windows.Forms.Application.Run(Form mainForm) at ABC.Program.Main() in C:\Documents and Settings\...\Program.cs:line 17 InnerException: 

这很难重现exception,是非常难以预测的。 我附加了我的visual studio调试器并运行了7到10次测试,并且能够成功捕获此堆栈跟踪。 请注意,这些都不是我的代码,因此在Windows级别发生了一些令人毛骨悚然的事情。 顺便说一句,我们使用PInvoke打开/关闭像iexplore,记事本等窗口。

经过一些 – 搜索 – 并根据微软那个人给出的建议我尝试了ADPlus来获取内存转储和Windbg进行分析,但是我从windbg获得的信息比exception本身更加神秘。

 This dump file has an exception of interest stored in it. The stored exception information can be accessed via .ecxr. (904.1cf4): Access violation - code c0000005 (first/second chance not available) eax=003c4d10 ebx=00000000 ecx=00000000 edx=00000000 esi=003c4d2a edi=0012f1a0 eip=003c4b64 esp=0012f11c ebp=0012f138 iopl=0 nv up ei pl zr na pe nc cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00010246 003c4b64 8b410c mov eax,dword ptr [ecx+0Ch] ds:0023:0000000c=???????? 0:000> .ecxr eax=003c4d10 ebx=00000000 ecx=00000000 edx=00000000 esi=003c4d2a edi=0012f1a0 eip=003c4b64 esp=0012f11c ebp=0012f138 iopl=0 nv up ei pl zr na pe nc cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00010246 003c4b64 8b410c mov eax,dword ptr [ecx+0Ch] ds:0023:0000000c=???????? 

可以有一些专家可以提供这些信息,我不能。

那么,你们做了什么来分析这些问题呢? 对于.Net来说,像“JVM的堆转储分析器”这样的东西?

环境:Windows XP SP3 [完全访问权限,管理员]

在Visual Studio中,转到项目属性并启用“非托管代码取消”,然后启动调试器。

[不确定是否需要以下步骤,但我只是这样做]在Visual Studio的立即窗口中执行.load SOS.dll

我找到了问题的根本原因在“ABC.Form1 + SendMessageDelegate :: Invoke”类型的垃圾收集委托上进行了回调。 这可能会导致应用程序崩溃,损坏和数据丢失。 将委托传递给非托管代码时,托管应用程序必须保持它们的活动状态,直到确保它们永远不会被调用。

感谢所有发表回复或评论的人。

Interesting Posts