内存损坏错误

8

我制作了一个C#应用程序,用于房地产经纪人管理。

在该应用程序中,我有一个包含所有菜单的MDI表单。

在该菜单中,当我选择代理商主控时,会出现一个带有添加代理商按钮的表单。

当点击“添加代理商”按钮时,另一个窗口将打开,以填写代理商详细信息。

我的问题是>> 当我关闭这个表单时>>

"Attempt to read or write protected memory.This often an indication that other memory is corrupt"

出现错误。

当我点击应用程序中的消息框上的“确定”按钮时,整个应用程序都会关闭。

当我通过Visual Studio正常运行应用程序时,不会出现此错误。

但是,当我运行代码的exe文件时,就会出现此错误。

这个错误有解决方案吗?

我在发布或调试项目时犯了什么错误吗?

我的堆栈跟踪:

See the end of this message for details on invoking 
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
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.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.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


************** Loaded Assemblies **************
mscorlib
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.5420 (Win7SP1.050727-5400)
    CodeBase: file:///C:/Windows/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll
----------------------------------------
Anamol Estate
    Assembly Version: 1.0.0.0
    Win32 Version: 1.0.0.0
    CodeBase: file:///E:/Anamol%20Estate/Anamol%20Estate/Anamol%20Estate/bin/x86/Release/Anamol%20Estate.exe
----------------------------------------
System.Windows.Forms
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.5420 (Win7SP1.050727-5400)
    CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.5420 (Win7SP1.050727-5400)
    CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Drawing
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.5420 (Win7SP1.050727-5400)
    CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
System.Data
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.5420 (Win7SP1.050727-5400)
    CodeBase: file:///C:/Windows/assembly/GAC_32/System.Data/2.0.0.0__b77a5c561934e089/System.Data.dll
----------------------------------------
System.Xml
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.5420 (Win7SP1.050727-5400)
    CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Xml/2.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------
System.Transactions
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.4927 (NetFXspW7.050727-4900)
    CodeBase: file:///C:/Windows/assembly/GAC_32/System.Transactions/2.0.0.0__b77a5c561934e089/System.Transactions.dll
----------------------------------------
System.EnterpriseServices
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.5420 (Win7SP1.050727-5400)
    CodeBase: file:///C:/Windows/assembly/GAC_32/System.EnterpriseServices/2.0.0.0__b03f5f7f11d50a3a/System.EnterpriseServices.dll
----------------------------------------
System.Configuration
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.5420 (Win7SP1.050727-5400)
    CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Configuration/2.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
----------------------------------------

************** JIT Debugging **************
To enable just-in-time (JIT) debugging, the .config file for this
application or computer (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.

For example:

<configuration>
    <system.windows.forms jitDebugging="true" />
</configuration>

启用JIT调试时,任何未处理的异常都将发送到计算机上注册的JIT调试器,而不是由此对话框处理。

4
你有任何COM或未受管控的Interop吗? - Daniel A. White
3
你正在使用哪些第三方库? - Zdeslav Vojkovic
4
我认为你首先需要学习有关计算机程序如何执行、函数调用、堆栈等基础知识。如果我的话听起来有些无礼,那并不是我的本意,但你缺少一些基本的东西。我不知道该怎么帮助你。 - Zdeslav Vojkovic
3
如果错误只在关闭时发生,那么似乎有些东西正在尝试访问一个刚被处理掉的控件/资源。为了找出原因,我建议在关闭窗体之前尽可能禁用多余的功能。例如,如果您有任何后台线程或计时器运行,请在关闭之前手动停止它们。如果您有任何数据绑定或验证/on leave事件,请禁用它们。如果所有这些都无效,您可能需要复制项目并逐步去除其中的部分,直到要么能够解决问题,要么得到一个出错的简单示例。 - sgmoore
3
请提供开放表单周围的代码和代理主表单内部的代码,以便我们可以修复您的问题。 - Mohsen Afshin
显示剩余20条评论
2个回答

3

.NET Framework也有类似的问题。请尝试这个修复程序

当你运行Microsoft .NET Framework 2.0 Remoting应用程序时,可能会收到以下错误信息: 未处理的异常:System.AccessViolationException:尝试读取或写入受保护的内存。这通常是其他内存已经损坏的迹象。 此外,在运行某些类型的驱动程序软件或防病毒程序的计算机上,.NET Framework 2.0 Remoting应用程序也可能出现此问题。


我应该下载那个热补丁吗?问题会得到解决吗?还是某些地方也在告诉我要等待下一个版本的发布。 - Freelancer
这个原因可能是最有可能的。还有其他原因,但我需要更多关于这个问题的信息。尝试执行这个修复程序。在这种情况下,您没有任何风险。 - Roman Melnyk
链接已失效。 - StayOnTarget

0

首先,您可以尝试运行memtest,因为可能存在特定的内存扇区,当分配给它时会导致此错误。最新版本是4.2,下载部分需要向下滚动一段时间。

或者

我曾经遇到过这种情况,那是由于病毒更改了我的exe文件头。在我的情况下,我格式化了电脑并重新安装了所有软件,然后问题得到了解决。我建议您尝试这个选项。


但我已经在3台不同的计算机上安装了它,它们全部都出现了问题。 - Freelancer
抱歉,我不知道问题可能来自哪里。 - Enzero

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接