2017-04-06 89 views
1

在Windows 7上使用Windows窗体在Visual Studio 2017中获取以下错误。这种情况发生在多台计算机上。我在标签中有一组编辑框,当在组合框中选择一个“表单”时,它们都被设置为隐藏或可见。我会将文本导入到这些编辑框中,滚动滚动或通过组合框的上/下箭头选择要显示或隐藏的不同标签,最终这些窗体中的编辑框会变为空白。当你去输入编辑框时,你会得到内存错误。我搜索并搜索了一个没有运气的解决方案。任何帮助将非常感激。C#保护内存错误,缓慢地杀死我的大脑

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()); } 
+0

我们可以看到一些代码吗?你能提供一个再现问题的最简单的例子吗?我们也从查看鼠标滚轮和查看事件处理程序开始。 – khargoosh

+0

就处理程序而言,我没有使用鼠标滚轮进行任何设置。我甚至不知道代码的哪一部分导致了这一点。这似乎是一个普遍的错误,我不知道在哪里查明确切原因。 – DasGoat

+1

你在做任何p/invoke调用吗?开始从应用程序中删除东西,直到问题消失。那么你至少缩小了它的范围。然后...向我们展示代码。 – khargoosh

回答

0

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