views:

1247

answers:

5

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! :-)

A: 

It looks like you're using a custom combo box control called AutoCompleteCombo. I would suspect that the WndProc override in that class has a bug in it - probably changing the value of the message parameter. Can you post that method's code so we can have a look?


There's nothing in the code that you posted that would cause a problem. You should probably look at the rest of AutoCompleteCombo's code for potential bugs. There's not really anything else to go on.

Stu Mackellar
+2  A: 

I have a strange non-deterministic feeling with the OutOfMemoryException in your code.

Why do you need that? And if you need it, may this be the cause of your problems? OutOfMemoryExceptions are very rare. If you have these, I would think it is a strong indication something else is wrong.

GvS
A: 

Thanks for your input, GvS and Stu. I'm doing a bit more probing re the OutOfMemory and found an interesting way this may happen (adding two items to the combo that return Nothing in their ToString override - http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=247053&SiteID=1 )

Sparky
A: 

I have just found that the original exception (AccessViolationException) is also caused by having an item in the ComboBox whose ToString returns Nothing (null). I don't know why you sometimes get OutOfMemory, sometimes Accessviolation and sometimes a NullReference exception.

pipTheGeek
A: 

Shot in the dark, but maybe you are trying to modify the AutoComplete list during a KeyDown, KeyUp, or KeyPress event?

That can cause access violations according to Microsoft.

Special Touch