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、メモ帳などのウィンドウを開いたり閉じたりします。

いくつか(検索)した後、Microsoftのその人からのアドバイスに基づいて、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=????????

この情報を理解できる専門家がいる可能性がありますが、私にはできません。

それで、あなたたちはこの種の問題を分析するために何をしますか?.Netの「JVM用ヒープダンプアナライザ」のようなものはありますか?

環境:Windows XP SP3 [フルアクセス、管理者]

4

1 に答える 1

2

Visual Studioで、プロジェクトのプロパティに移動し、「アンマネージコードのデガビング」を有効にしてから、デバッガーを起動します。

[以下の手順が必要かどうかはわかりませんが、実行しました]VisualStudioのイミディエイトウィンドウで.loadSOS.dllを実行します

問題の根本的な原因を見つけることができましたタイプ'ABC.Form1 + SendMessageDelegate::Invoke'のガベージコレクションされたデリゲートでコールバックが行われました。これにより、アプリケーションのクラッシュ、破損、データの損失が発生する可能性があります。デリゲートをアンマネージコードに渡す場合、デリゲートが呼び出されないことが保証されるまで、デリゲートはマネージアプリケーションによって存続する必要があります。

返信やコメントを投稿してくださった皆様、ありがとうございました。

于 2011-02-15T17:35:50.907 に答える