开发者

Windows Forms ComboBox causing intermittent System.AccessViolationException

Some back story:

I have searched both stackoverflow and Google to figure out the origin of this particular exception.

We have a Windows Forms (C#, .NET 2.0) application that will occasionally throw a System.AccessViolationException (stack trace below). The exception has occurred on both Windows XP (SP3) and Windows Vista (SP2). From user input, we have pinned down that the exception occurs when the selected index of a ComboBox is changed.

The ComboBox is a standard Windows Forms component, and it is contained in a custom control that inherits System.Windows.Forms.UserControl.

My main query is:

Where does this exception come from?

  • Is it from some internal bug in the .NET framework?
  • Could it be code that is dispatched on the SelectedIndexChanged event that causes it?

Related topics on stackoverflow:

  • finding the cause of System.AccessViolationException - Mentions that this exception is equivalent to an unhandled exception, only that it's caught by the .NET runtime rather than the OS.
  • Can a System.AccessViolationException happen because of faulty RAM? - Considers faulty RAM as the culprit. However possible, I don't find it very plausible since it has occurred on a number of different machines recently. The probability of all of them having faulty RAM is low.

Stack trace开发者_Go百科:

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)


I had these problems as well, way back when I used .net 2.0 WinForms. I seem to remember Microsoft released a Hotfix for this. I googled it and found these two. You could try them.

http://support.microsoft.com/kb/923028

http://support.microsoft.com/kb/971030

Also, did you install all Service Packs for .NET 2.0?


Don't give it a chance to overload memory, dispose all your new and unused items/controls Do not constanly add/remove objects to a listbox, typically during thread operations.

GDI problems occur if you don't clear the memory.

Combobox exceptions occur, it may have something related to the selecteditem, whether that item has text or an integer stored. Text must be text, integer must be integer.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜