Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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:

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)
like image 752
Christoffer Avatar asked May 31 '11 09:05

Christoffer


1 Answers

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?

like image 101
Edwin de Koning Avatar answered Nov 03 '22 05:11

Edwin de Koning