AccessViolationException from combo: attempt to read or write protected memory

Users sometimes get the above error when using our application (VB.Net, Winforms, using v2 as part of the framework). I can not reproduce it. The column is as follows:

: System.AccessViolationException: Attempted to read or write protected memory. This often indicates that another memory is corrupted. in System.Windows.Forms.UnsafeNativeMethods.CallWindowProc (IntPtr wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam) in System.Windows.Forms.NativeWindow.DefWndProc (Message & m) in System.WindowsF. DefWndProc (Message & m) in System.Windows.Forms.Control.WndProc (Message & m) in System.Windows.Forms.ComboBox.WndProc (Message & m) in ControlEx.AutoCompleteCombo.WndProc (Message & m) in System. Windows.Forms.Control.ControlNativeWindow.OnMessage (Message & m) in System.Windows.Forms.Control.ControlNativeWindow.WndProc (Message & m) in System.Windows.Forms.NativeWindow.Callback (IntPtr hWnd, Int32 msg, IntPtr wparam , IntPtr lparam)

The ControlEx.AutoCompleteCombo.WndProc code 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

Error handling has been added, so we can determine which combination causes the problem when we get an OutOfMemoryException.

Any clues as to what causes this would be greatly appreciated !:-)

+3
source share
5 answers

I have a weird non-deterministic feeling with an OutOfMemoryException in your code.

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

+1
source

, , AutoCompleteCombo. , WndProc - , . , ?


, , . , AutoCompleteCombo . .

0

, GvS Stu. OutOfMemory , ( , Nothing ToString - http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=247053&SiteID=1)

0

, (AccessViolationException) ComboBox, ToString Nothing (null). , OutOfMemory, Accessviolation NullReference.

0

, , , KeyDown, KeyUp KeyPress?

This may cause access violations according to Microsoft.

0
source

Source: https://habr.com/ru/post/1699120/


All Articles