AccessViolationException from a combo: Attempted to read or write protected memory
Posted
by Sparky
on Stack Overflow
See other posts from Stack Overflow
or by Sparky
Published on 2008-11-04T16:42:11Z
Indexed on
2010/04/07
22:03 UTC
Read the original article
Hit count: 609
Users are occassionally getting the above error when using our application (VB.Net, Winforms, using v2 of the framework). I'm not able to reproduce it. The callstack is as follows:
: System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt. 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.WndProc(Message& m) at System.Windows.Forms.ComboBox.WndProc(Message& m) at ControlEx.AutoCompleteCombo.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)
The code for ControlEx.AutoCompleteCombo.WndProc is as follows:
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
Try
If Not m_fReadOnly Then
MyBase.WndProc(m)
Else
Select Case m.Msg
Case WM_LBUTTONDOWN, WM_LBUTTONDBLCLK
' do nothing
Case Else
MyBase.WndProc(m)
End Select
End If
Catch ex As OutOfMemoryException
Throw New OutOfMemoryException("Exception during WndProc for combo " & Me.Name, ex)
End Try
End Sub
The error handling was added so we can determine which combo causes the problem when we get an OutOfMemoryException.
Any clues as to what causes this would be muchly appreciated! :-)
© Stack Overflow or respective owner