未处理且无法捕获的 System.AccessViolationException
在对我们的应用程序进行压力测试时,我们似乎总是在使用大约 10-12 小时后遇到灾难性的 AccessViolationException。
使用 WinDbg 来定位源,我发现它似乎源自本机表单的消息循环。如果有人能证实我的怀疑,那就太好了,所以我包含了带有参数的完整堆栈跟踪。如果有人需要更多信息,我还进行了完整的堆栈跟踪。
提前致谢!
0:000> !CLRStack -p 操作系统线程 ID: 0x748 (0) ESP EIP
0012d44c 7c90e514 [InlinedCallFrame: 0012d44c] 系统.Windows.Forms.UnsafeNativeMethods.WaitMessage() 0012d448 7b1d8ed8 System.Windows.Forms.Application+ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32, Int32、Int32) 参数: 这= 0x015fe94c dwComponentID = 原因=0x00000004 pvLoopData = 0x000000000012d4e4 7b1d89c7 System.Windows.Forms.Application+ThreadContext.RunMessageLoopInner(Int32, 系统.Windows.Forms.ApplicationContext) 参数: 这= 0x0153d9ec 原因=0x00000004 上下文 = 0x0226ec58
0012d538 7b1d8811 System.Windows.Forms.Application+ThreadContext.RunMessageLoop(Int32, 系统.Windows.Forms.ApplicationContext) 参数: 这= 原因= 上下文=
0012d568 7b6ede47 System.Windows.Forms.Application.RunDialog(System.Windows.Forms.Form) 参数: 形式=
0012d57c 7b7225cb System.Windows.Forms.Form.ShowDialog(System.Windows.Forms.IWin32Window) 参数: 这= 0x02265860 所有者 =
0012d608 7b7227e3 System.Windows.Forms.Form.ShowDialog() 参数: 这=
0012d60c 7b6eefa2 System.Windows.Forms.Application+ThreadContext.OnThreadException(System.Exception) 参数: 这= 0x0153d9ec t = 0x02265600
0012d648 7b6f7936 System.Windows.Forms.Control.WndProcException(系统异常) 参数: 这= e =
0012d654 7b6fa3bc System.Windows.Forms.Control+ControlNativeWindow.OnThreadException(System.Exception) 参数: 这= e =
0012d658 7b1c8502 System.Windows.Forms.NativeWindow.Callback(IntPtr, Int32、IntPtr、IntPtr) 参数: 这= 0x01a9c930 hWnd = 消息 = 0x00000002 参数= l 参数 =
0012e880 003c25e4 [NDirectMethodFrameStandalone:0012e880] System.Windows.Forms.UnsafeNativeMethods.IntDestroyWindow(System.Runtime.InteropServices.HandleRef) 0012e898 7b19ec50 System.Windows.Forms.UnsafeNativeMethods.DestroyWindow(System.Runtime.InteropServices.HandleRef) 参数: hWnd =
0012e8a8 7b19eb5a System.Windows.Forms.NativeWindow.DestroyHandle() 参数: 这= 0x01a96d08
0012e8ec 7b1b9050 System.Windows.Forms.Control.DestroyHandle() 参数: 这= 0x01a967a8
0012e8f0 7b7226bc [InlinedCallFrame: 0012e8f0] 0012ea04 7b7227e3 System.Windows.Forms.Form.ShowDialog() 参数: 这=
0012ea08 04bf3a7b Workstation.FrontScreenForm.HandleNewEvent(GroupsRow,Int16,Int64) 参数: 这= 0x0153b26c 组 = 0x01a8de34 事件类型 ID = 0x00000003 上一个事件ID = 0xffffffff
0012ec50 04bf344f Workstation.FrontScreenForm.HandleNewEvent(GroupsRow, Int16) 参数: 这= 0x0153b26c 组 = 0x01a8de34 事件类型ID = 0x00000003
0012ec64 04b21ac4 Workstation.FrontScreenForm.btnSiteCheck_Click(System.Object, 系统.EventArgs) 参数: 这= 0x0153b26c 发件人 = 0x01546a44 e = 0x0153e990
0012ecd4 7b194180 System.Windows.Forms.Control.OnClick(System.EventArgs) 参数: 这= e =
0012ecec 7b18f56a System.Windows.Forms.Button.OnClick(System.EventArgs) 参数: 这= e =
0012ecfc 7b734429 System.Windows.Forms.ButtonBase.OnKeyUp(System.Windows.Forms.KeyEventArgs) 参数: 这= 0x01546a44 kevent = 0x01a914c0
0012ed0c 7b6f5bf1 System.Windows.Forms.Control.ProcessKeyEventArgs(System.Windows.Forms.Message 参考) 参数: 这= 0x01546a44 m = 0x0012ee44
0012ed5c 7b6f5c95 System.Windows.Forms.Control.ProcessKeyMessage(System.Windows.Forms.Message 参考) 参数: 这= 米=
0012ed6c 7b6f7381 System.Windows.Forms.Control.WmKeyChar(System.Windows.Forms.Message 参考) 参数: 这= 0x01546a44 m = 0x0012ee44
0012ed7c 7ba2a0ee System.Windows.Forms.Control.WndProc(System.Windows.Forms.Message 参考) 参数: 这= 米=
0012ed80 7b1c2626 [InlinedCallFrame: 0012ed80] 0012ee18 7b1c25a0 System.Windows.Forms.Button.WndProc(System.Windows.Forms.Message 参考) 参数: 这= 米=
0012ee24 7b1c8690 System.Windows.Forms.Control+ControlNativeWindow.OnMessage(System.Windows.Forms.Message 参考) 参数: 这= 米=
0012ee2c 7b1c8611 System.Windows.Forms.Control+ControlNativeWindow.WndProc(System.Windows.Forms.Message 参考) 参数: 这= 米=
0012ee40 7b1c84ea System.Windows.Forms.NativeWindow.Callback(IntPtr, Int32、IntPtr、IntPtr) 参数: 这= 0x01546b14 hWnd = 消息 = 0x00000101 参数= l 参数 =
0012f220 003c25e4 [NDirectMethodFrameStandalone: 0012f220] System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG ByRef) 0012f230 7b1d8d5e System.Windows.Forms.Application+ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32, Int32、Int32) 参数: 这= 0x015fe94c dwComponentID = 原因=0xffffffff pvLoopData = 0x00000000
0012f2cc 7b1d89c7 System.Windows.Forms.Application+ThreadContext.RunMessageLoopInner(Int32, 系统.Windows.Forms.ApplicationContext) 参数: 这= 0x0153d9ec 原因=0xffffffff 上下文 = 0x015fdcd4
0012f320 7b1d8811 System.Windows.Forms.Application+ThreadContext.RunMessageLoop(Int32, 系统.Windows.Forms.ApplicationContext) 参数: 这= 原因= 上下文=
0012f350 7b195921 System.Windows.Forms.Application.Run(System.Windows.Forms.Form) 参数: 主窗体 =
0012f364 00f809df 工作站.Program.Main() 0012f688 79e71b4c [GC帧:0012f688]
While stress testing our application we always seem to suffer a catastrophic AccessViolationException after around 10-12 hours of use.
Using WinDbg to locate the source I see that it seems to originate from the native form's message loop. It would be great if someone would confirm my suspicion so I include a full stack trace with parameters. I have also taken a full stack trace if anyone needs more information.
Thanks in advance!
0:000> !CLRStack -p OS Thread Id: 0x748 (0) ESP EIP
0012d44c 7c90e514 [InlinedCallFrame: 0012d44c]
System.Windows.Forms.UnsafeNativeMethods.WaitMessage() 0012d448
7b1d8ed8
System.Windows.Forms.Application+ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32,
Int32, Int32)
PARAMETERS:
this = 0x015fe94c
dwComponentID =
reason = 0x00000004
pvLoopData = 0x000000000012d4e4 7b1d89c7
System.Windows.Forms.Application+ThreadContext.RunMessageLoopInner(Int32,
System.Windows.Forms.ApplicationContext)
PARAMETERS:
this = 0x0153d9ec
reason = 0x00000004
context = 0x0226ec580012d538 7b1d8811
System.Windows.Forms.Application+ThreadContext.RunMessageLoop(Int32,
System.Windows.Forms.ApplicationContext)
PARAMETERS:
this =
reason =
context =0012d568 7b6ede47
System.Windows.Forms.Application.RunDialog(System.Windows.Forms.Form)
PARAMETERS:
form =0012d57c 7b7225cb
System.Windows.Forms.Form.ShowDialog(System.Windows.Forms.IWin32Window)
PARAMETERS:
this = 0x02265860
owner =0012d608 7b7227e3 System.Windows.Forms.Form.ShowDialog()
PARAMETERS:
this =0012d60c 7b6eefa2
System.Windows.Forms.Application+ThreadContext.OnThreadException(System.Exception)
PARAMETERS:
this = 0x0153d9ec
t = 0x022656000012d648 7b6f7936
System.Windows.Forms.Control.WndProcException(System.Exception)
PARAMETERS:
this =
e =0012d654 7b6fa3bc
System.Windows.Forms.Control+ControlNativeWindow.OnThreadException(System.Exception)
PARAMETERS:
this =
e =0012d658 7b1c8502 System.Windows.Forms.NativeWindow.Callback(IntPtr,
Int32, IntPtr, IntPtr)
PARAMETERS:
this = 0x01a9c930
hWnd =
msg = 0x00000002
wparam =
lparam =0012e880 003c25e4 [NDirectMethodFrameStandalone: 0012e880]
System.Windows.Forms.UnsafeNativeMethods.IntDestroyWindow(System.Runtime.InteropServices.HandleRef)
0012e898 7b19ec50
System.Windows.Forms.UnsafeNativeMethods.DestroyWindow(System.Runtime.InteropServices.HandleRef)
PARAMETERS:
hWnd =0012e8a8 7b19eb5a System.Windows.Forms.NativeWindow.DestroyHandle()
PARAMETERS:
this = 0x01a96d080012e8ec 7b1b9050 System.Windows.Forms.Control.DestroyHandle()
PARAMETERS:
this = 0x01a967a80012e8f0 7b7226bc [InlinedCallFrame: 0012e8f0] 0012ea04 7b7227e3
System.Windows.Forms.Form.ShowDialog()
PARAMETERS:
this =0012ea08 04bf3a7b
Workstation.FrontScreenForm.HandleNewEvent(GroupsRow, Int16, Int64)
PARAMETERS:
this = 0x0153b26c
Group = 0x01a8de34
EventTypeID = 0x00000003
previousEventID = 0xffffffff0012ec50 04bf344f
Workstation.FrontScreenForm.HandleNewEvent(GroupsRow, Int16)
PARAMETERS:
this = 0x0153b26c
Group = 0x01a8de34
EventTypeID = 0x000000030012ec64 04b21ac4
Workstation.FrontScreenForm.btnSiteCheck_Click(System.Object,
System.EventArgs)
PARAMETERS:
this = 0x0153b26c
sender = 0x01546a44
e = 0x0153e9900012ecd4 7b194180
System.Windows.Forms.Control.OnClick(System.EventArgs)
PARAMETERS:
this =
e =0012ecec 7b18f56a
System.Windows.Forms.Button.OnClick(System.EventArgs)
PARAMETERS:
this =
e =0012ecfc 7b734429
System.Windows.Forms.ButtonBase.OnKeyUp(System.Windows.Forms.KeyEventArgs)
PARAMETERS:
this = 0x01546a44
kevent = 0x01a914c00012ed0c 7b6f5bf1
System.Windows.Forms.Control.ProcessKeyEventArgs(System.Windows.Forms.Message
ByRef)
PARAMETERS:
this = 0x01546a44
m = 0x0012ee440012ed5c 7b6f5c95
System.Windows.Forms.Control.ProcessKeyMessage(System.Windows.Forms.Message
ByRef)
PARAMETERS:
this =
m =0012ed6c 7b6f7381
System.Windows.Forms.Control.WmKeyChar(System.Windows.Forms.Message
ByRef)
PARAMETERS:
this = 0x01546a44
m = 0x0012ee440012ed7c 7ba2a0ee
System.Windows.Forms.Control.WndProc(System.Windows.Forms.Message
ByRef)
PARAMETERS:
this =
m =0012ed80 7b1c2626 [InlinedCallFrame: 0012ed80] 0012ee18 7b1c25a0
System.Windows.Forms.Button.WndProc(System.Windows.Forms.Message
ByRef)
PARAMETERS:
this =
m =0012ee24 7b1c8690
System.Windows.Forms.Control+ControlNativeWindow.OnMessage(System.Windows.Forms.Message
ByRef)
PARAMETERS:
this =
m =0012ee2c 7b1c8611
System.Windows.Forms.Control+ControlNativeWindow.WndProc(System.Windows.Forms.Message
ByRef)
PARAMETERS:
this =
m =0012ee40 7b1c84ea System.Windows.Forms.NativeWindow.Callback(IntPtr,
Int32, IntPtr, IntPtr)
PARAMETERS:
this = 0x01546b14
hWnd =
msg = 0x00000101
wparam =
lparam =0012f220 003c25e4 [NDirectMethodFrameStandalone: 0012f220]
System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG ByRef)
0012f230 7b1d8d5e
System.Windows.Forms.Application+ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32,
Int32, Int32)
PARAMETERS:
this = 0x015fe94c
dwComponentID =
reason = 0xffffffff
pvLoopData = 0x000000000012f2cc 7b1d89c7
System.Windows.Forms.Application+ThreadContext.RunMessageLoopInner(Int32,
System.Windows.Forms.ApplicationContext)
PARAMETERS:
this = 0x0153d9ec
reason = 0xffffffff
context = 0x015fdcd40012f320 7b1d8811
System.Windows.Forms.Application+ThreadContext.RunMessageLoop(Int32,
System.Windows.Forms.ApplicationContext)
PARAMETERS:
this =
reason =
context =0012f350 7b195921
System.Windows.Forms.Application.Run(System.Windows.Forms.Form)
PARAMETERS:
mainForm =0012f364 00f809df Workstation.Program.Main() 0012f688 79e71b4c
[GCFrame: 0012f688]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

访问冲突异常通常不会来自托管代码,这意味着您的操作系统认为该进程做了一些坏事(试图访问/更改不应访问/更改的内存)并且应该终止。
当您使用 Windbg 捕获异常(并转储)时,已经为时已晚。
一些选项:
An access violation exception will not usually come from managed code, it means that your OS decided the process has done something bad (trying to access/change memory where it shouldn't) and should be terminated.
when you catch the exception with windbg (and take the dump) it is already too late.
some options: