来自组合的 AccessViolationException:尝试读取或写入受保护的内存 [英] AccessViolationException from a combo: Attempted to read or write protected memory
问题描述
用户在使用我们的应用程序(VB.Net、Winforms、使用框架的 v2)时偶尔会遇到上述错误.我无法重现它.调用栈如下:
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: 试图读取或写入受保护的内存.这通常表明其他内存已损坏.在 System.Windows.Forms.UnsafeNativeMethods.CallWindowProc(IntPtr wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)在 System.Windows.Forms.NativeWindow.DefWndProc(Message& m)在 System.Windows.Forms.Control.DefWndProc(Message& m)在 System.Windows.Forms.Control.WndProc(Message& m)在 System.Windows.Forms.ComboBox.WndProc(Message& m)在 ControlEx.AutoCompleteCombo.WndProc(Message& m)在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)在 System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
: 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)
ControlEx.AutoCompleteCombo.WndProc的代码如下:
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
添加了错误处理,以便我们可以在遇到 OutOfMemoryException 时确定哪个组合导致了问题.
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! :-)
推荐答案
我对代码中的 OutOfMemoryException 有一种奇怪的不确定感.
I have a strange non-deterministic feeling with the OutOfMemoryException in your code.
你为什么需要那个?如果您需要它,这可能是您遇到问题的原因吗?OutOfMemoryExceptions 非常罕见.如果你有这些,我认为这是一个强烈的迹象,表明其他地方出了问题.
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.
这篇关于来自组合的 AccessViolationException:尝试读取或写入受保护的内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!