【发布时间】:2011-09-05 08:19:34
【问题描述】:
一些背景故事:
我已经搜索了 stackoverflow 和 Google,以找出这个特定异常的来源。
我们有一个 Windows 窗体(C#、.NET 2.0)应用程序,它偶尔会抛出 System.AccessViolationException(下面的堆栈跟踪)。在 Windows XP (SP3) 和 Windows Vista (SP2) 上都发生了异常。根据用户输入,我们已经确定当 ComboBox 的选定索引发生更改时会发生异常。
ComboBox 是标准的 Windows 窗体组件,它包含在继承 System.Windows.Forms.UserControl 的自定义控件中。
我的主要查询是:
这个异常从何而来?
- 是来自 .NET 框架中的一些内部错误吗?
- 会不会是在
SelectedIndexChanged事件上调度的代码导致了它?
stackoverflow 上的相关主题:
- finding the cause of System.AccessViolationException - 提到此异常等同于未处理的异常,只是它是由 .NET 运行时而不是操作系统捕获的。
- Can a System.AccessViolationException happen because of faulty RAM? - 认为有故障的 RAM 是罪魁祸首。然而可能,我觉得它不太合理,因为它最近发生在许多不同的机器上。所有这些内存都出现故障的概率很低。
堆栈跟踪:
Message: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
Type: System.AccessViolationException
at System.Windows.Forms.UnsafeNativeMethods.CallWindowProc(IntPtr wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at System.Windows.Forms.NativeWindow.DefWndProc(Message& m)
at System.Windows.Forms.Control.DefWndProc(Message& m)
at System.Windows.Forms.Control.WmCommand(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ComboBox.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
【问题讨论】:
标签: c# winforms exception-handling combobox .net-2.0