C#保护内存错误慢慢杀死我的大脑

时间:2017-04-06 22:44:36

标签: c# visual-studio

在Windows 7上使用Windows窗体在Visual Studio 2017中获取以下错误。这种情况发生在多台计算机上。我在标签中有一组编辑框,所有这些编辑框都设置为隐藏或在选择"表格时可见。在一个组合框中。发生的事情是我将文本导入这些编辑框,滚轮滚动或向上/向下箭头,通过形式组合框选择要显示或隐藏的不同标签,这样做最终这些形式之一的编辑框变为空白。当您输入编辑框时,会出现内存错误。我搜索并搜索了一个没有运气的解决方案。任何帮助都会非常感激。

    System.AccessViolationException occurred
    HResult=0x80004003
    Message=Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
    Source=System.Windows.Forms
    StackTrace:
    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.WmKeyChar(Message& m)
    at System.Windows.Forms.Control.WndProc(Message& m)
    at System.Windows.Forms.TextBoxBase.WndProc(Message& m)
    at System.Windows.Forms.TextBox.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.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
    at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
    at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop        (IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
    at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
    at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
    at System.Windows.Forms.Application.Run(Form mainForm)
    at Notes.Program.Main() in documents\visual studio 2017\Projects\Notes\Notes\Program.cs:line 19

导入编辑框的代码为空白。

List<string> ort = imp.Split(new[] { Environment.NewLine }, StringSplitOptions.None).ToList();
//Name regex match
var match = new Regex(@"((?<=: ).*(?=\[))");
var name = match.Match(ort[0]);
if (tChoice == 0) { user.Text = String.Empty; user.AppendText(name.Groups[0].ToString()); }
if (tChoice == 1) { pwuser.Text = String.Empty; pwuser.AppendText(name.Groups[0].ToString()); }
if (tChoice == 2)
{
    gmmuser.Text = String.Empty; requser.Text = String.Empty; reqAuser.Text = String.Empty; billuser.Text = String.Empty;
    gmmuser.AppendText(name.Groups[0].ToString()); requser.AppendText(name.Groups[0].ToString()); reqAuser.AppendText(name.Groups[0].ToString()); billuser.AppendText(name.Groups[0].ToString());
}
if (tChoice == 3) { emailuser.Text = String.Empty; emailuser.AppendText(name.Groups[0].ToString()); }

1 个答案:

答案 0 :(得分:0)

实际上看起来它可能与目标框架有关。我把它设置为4.6.2。我把它设置为4.5.2并且尚未遇到问题,手指交叉。