2011-02-15 98 views
2

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: 

這很難重現異常,是非常不可預知的。我附加了我的visual studio調試器並運行測試7-10次,並能夠成功捕獲此堆棧跟蹤。請注意,這些都不是我的代碼,所以在windows級別發生一些令人髮指的事情。順便說一句,我們使用的PInvoke打開/關閉的窗戶像IEXPLORE,記事本等調試winform崩潰 - C#[ADPlus + Windbg]

經過一番 - search - 並根據建議被那個傢伙從微軟我試圖ADPlus的獲得內存轉儲& WinDBG的分析得到,但我從windbg得到的信息比例外本身更加神祕。


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=???????? 

可以有一些專家,可以使這些信息SENCE,我不能。

那麼,你們如何分析這類問題呢?任何類似於.Net的「JVM堆轉儲分析器」

環境:Windows XP SP3 [完全訪問權限,管理員]

+0

什麼是您的環境和操作系統用戶帳戶訪問? – 2011-02-15 16:40:10

+0

運行WinDbg命令時是否加載了符號和SOS.dll?如果是這樣,你可以試試`!analyze -v`獲取更多信息 - 如果沒有,那麼我建議你從那裏開始! – 2011-02-15 16:43:19

回答

2

在Visual Studio中,轉到項目屬性,使 「非託管代碼degubbing」,然後啓動調試器。

[不知道下面的步驟是必需的,但我只是做了它] 在即時窗口執行的Visual Studio .load SOS.dll

我能找到問題的根本原因:一回調是在'ABC.Form1 + SendMessageDelegate :: Invoke'類型的垃圾收集委託上進行的。這可能會導致應用程序崩潰,損壞和數據丟失。在將代理傳遞給非託管代碼時,它們必須由託管應用程序保持活動狀態,直到確保它們永遠不會被調用。

感謝大家誰發佈了回覆或評論。