尝试读取或写入受保护的内存

发布于 2024-07-14 11:13:13 字数 2414 浏览 7 评论 0原文

我开始看到我的应用程序中的几个不同位置抛出了 AccessViolationException。 它从未发生在我的开发电脑、我们的测试服务器上。 它也只出现在我们 2 台生产服务器中的 1 台上。 因为它似乎只发生在我们的一台生产服务器上,所以我开始查看服务器上安装的 .net 框架版本。


我发现(由于某些奇怪的原因),出现问题的生产服务器有 2.0 sp2、3.0 sp2 和 3.5 sp1,而其他生产服务器和测试服务器有 2.0 sp1。


我的应用程序仅针对2.0框架,决定从生产服务器卸载所有框架版本并仅安装2.0 sp1。 到目前为止我还无法重现这个问题。 很有意思。

开发电脑:compact 2.0 sp2、compact 3.5、2.0 sp2、3.0 sp2、3.5 sp1 测试服务器:2.0 sp1 生产服务器1:2.0 sp1 生产服务器2:2.0 sp2、3.0 sp2、3.5 sp1

现在,为什么我无法在装有 2.0 sp2 的开发电脑上重现该问题,我不明白。 我听说有传言说这种访问冲突可能会发生在某些使用远程处理的软件上,我的软件就是如此,但当远程处理实际发生时,访问冲突从未发生过。 我现在可以只使用 2.0 sp1,但我真的很想知道是否有人遇到过这个问题,以及他们是否找到了新版本框架的解决方法。

以下是一些异常及其堆栈跟踪:

System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
   at ICSharpCode.TextEditor.TextArea.HandleKeyPress(Char ch)
   at ICSharpCode.TextEditor.TextArea.SimulateKeyPress(Char ch)
   at ICSharpCode.TextEditor.TextArea.OnKeyPress(KeyPressEventArgs e)
   at System.Windows.Forms.Control.ProcessKeyEventArgs(Message& m)
   at System.Windows.Forms.Control.ProcessKeyMessage(Message& m)
   at System.Windows.Forms.Control.WmKeyChar(Message& m)
   at System.Windows.Forms.Control.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)

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.RichTextBox.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)

I've started seeing an AccessViolationException being thrown in my application a several different spots. It never occured on my development pc, our test server. It also only manifested itself on 1 of our 2 production servers. Because it only seemed to happen on one of our production servers, I started looking at the installed .net framework versions on the servers.

I found that (for some strange reason), the production server that was having problems had 2.0 sp2, 3.0 sp2, and 3.5 sp1, while the other production server and the test server had 2.0 sp1.

My app only targets the 2.0 framework, decided to uninstall all the framework versions from the production server and install only 2.0 sp1. So far I have not been able to reproduce the problem. Very interesting.

Development pc: compact 2.0 sp2, compact 3.5, 2.0 sp2, 3.0 sp2, 3.5 sp1
Test server: 2.0 sp1
Production server1: 2.0 sp1
Production server2: 2.0 sp2, 3.0 sp2, 3.5 sp1

Now, why I can't reproduce the problem on my development pc which has 2.0 sp2 on it, I can't figure out. I heard rumors that this access violation may happen on some software that utilizes remoting, which mine does, but the access violation never happends when remoting is actually occuring. I'm ok with using only 2.0 sp1 for now, but I'm really interested to know if anyone has had this issue, and if they found a workaround for newer versions of the frameowork.

Here's a couple of the exceptions and their stack traces:

System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
   at ICSharpCode.TextEditor.TextArea.HandleKeyPress(Char ch)
   at ICSharpCode.TextEditor.TextArea.SimulateKeyPress(Char ch)
   at ICSharpCode.TextEditor.TextArea.OnKeyPress(KeyPressEventArgs e)
   at System.Windows.Forms.Control.ProcessKeyEventArgs(Message& m)
   at System.Windows.Forms.Control.ProcessKeyMessage(Message& m)
   at System.Windows.Forms.Control.WmKeyChar(Message& m)
   at System.Windows.Forms.Control.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)

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.RichTextBox.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)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(14

怎会甘心 2024-07-21 11:13:14

该问题可能是由于项目中的混合构建平台 DLL 造成的。 即您将项目构建到任何 CPU,但项目中已经为 x86 平台构建了一些 DLL。 由于 32 位和 64 位架构的内存映射不同,这些会导致随机崩溃。 如果所有 DLL 都是为一个平台构建的,那么问题就可以解决。 为了安全起见,尝试构建 32 位 x86 架构,因为它是最兼容的。

The problem may be due to mixed build platforms DLLs in the project. i.e You build your project to Any CPU but have some DLLs in the project already built for x86 platform. These will cause random crashes because of different memory mapping of 32bit and 64bit architecture. If all the DLLs are built for one platform the problem can be solved. For safety try bulinding for 32bit x86 architecture because it is the most compatible.

北方的韩爷 2024-07-21 11:13:14

就我而言,系统中未安装共享库之一中使用的字体。

In my case fonts used in one of the shared library was not installed in the system.

岁月染过的梦 2024-07-21 11:13:14

就我而言,我在添加对 COM DLL 的引用时遇到了“环境变量”的问题。

当我添加对项目的引用时,我正在寻找 P:\Core 路径,而我过去已将 c:\core 路径添加到路径环境变量中。

所以我的代码首先尝试错误的路径。 我删除了它并取消注册了 DLL 引用,并使用 (regsvr32) 重新注册了我的 DLL 引用。 希望这可以帮助。

In my case I had trouble with the "Environment variables" while adding reference to my COM DLL.

When I added the reference to my project, I was looking for P:\Core path, whereas I had added the c:\core path in past into path environment varaible.

So my code was attempting wrong path first. I removed that and un-registered the DLL reference and re-registered my DLL reference using (regsvr32). Hope this helps.

只怪假的太真实 2024-07-21 11:13:14

我在创建新项目时忘记添加EntityFramework导致了这个问题。

I forgot to add EntityFramework when creating a new project which caused this problem.

陪我终i 2024-07-21 11:13:13

从 .NET 4.5 升级到 .NET 4.5.1 后,我遇到了同样的问题。 对我来说解决这个问题的是运行这个命令:

netsh Winsock Reset

I had the same problem after upgrading from .NET 4.5 to .NET 4.5.1. What fixed it for me was running this command:

netsh winsock reset

嗫嚅 2024-07-21 11:13:13

我有同样的问题。
2.0 运行良好。 安装 3.5 sp1 之前的版本后,应用程序出现访问冲突。

安装了 http://support.microsoft.com/kb/971030 并且我的问题得到了解决,即使虽然我没有使用LCG。

I had the same problem.
2.0 worked fine. after installing up to 3.5 sp1, application gets Access Violation.

installed http://support.microsoft.com/kb/971030 and my problem is solved, even though I am not using LCG.

月亮邮递员 2024-07-21 11:13:13

Microsoft 还发布了一个修补程序(2007 年 7 月 2 日),以防止“尝试读取或写入受保护的内存”错误,该错误已经困扰 .NET 2.0 平台一段时间了。 查看 http://support.microsoft.com/kb/923028 - 不确定它是否适用给你,但我想你可能想看看。

Microsoft also released a hotfix (July 2nd, 2007) to prevent the error "Attempted to read or write protected memory" that has been plaguing the .NET 2.0 platform for some time now. Look at http://support.microsoft.com/kb/923028 - not sure if it applies to you, but thought you might like to check it out.

久随 2024-07-21 11:13:13

对于 VS 2013,.NET Framework 4.5.1 也有一个 AccessViolationException< /code> bug(KB2915689) 处理 SQL Server / TCP 套接字时。 升级到 .NET Framework 4.5.2 可以纠正此问题问题。

报VS.NET AccessViolationException

尝试读取或写入受保护的内存。 这通常表明其他内存已损坏。

For VS 2013, .NET Framework 4.5.1 also has a AccessViolationException bug (KB2915689) when dealing with SQL Server / TCP Sockets. Upgrading to .NET Framework 4.5.2 corrects this problem.

Reported VS.NET AccessViolationException

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

惜醉颜 2024-07-21 11:13:13

我正在使用 OLEDB,然后切换到 SQL 客户端,它解决了我的问题与此错误。

I was using OLEDB and I switched to SQL Client and it solved my problem with this error.

感情旳空白 2024-07-21 11:13:13

在某些 WinForms 上调用“Show”方法时,我通常会收到“尝试读取或写入受保护的内存”。 我查了一下,这些表格没有什么特别之处。 我不知道为什么会这样(也许有人可以告诉我),但通常将在表单的“Load”事件中执行的代码移动到“Shown”事件会为我修复它,我再也不会看到它了。

I usually get "Attempted to read or write protected memory" when calling the "Show" method on some WinForms. I checked and there doesn't appear anything special about those forms. I don't know why this works (maybe someone can tell me) but usually moving the code that gets executed in the "Load" event of the form to the "Shown" event fixes it for me and I never see it again.

月朦胧 2024-07-21 11:13:13

检查以确保线程内没有线程。 这就是导致我出现此错误的原因。 请参阅此链接:尝试读取或写入受保护的内存。 这通常表明其他内存已损坏

Check to make sure you don't have threads within threads. That's what caused this error for me. See this link: Attempted to read or write protected memory. This is often an indication that other memory is corrupt

夜灵血窟げ 2024-07-21 11:13:13

在某些情况下,在 VB.NET 中添加“Option Strict On”并通过正确的转换解决它发现的所有问题已经为我解决了这个问题。

In some cases adding "Option Strict On" in VB.NET and resolving all issues it finds by proper casting has solved this problem for me.

脸赞 2024-07-21 11:13:13

您好,有两个可能的原因。

  1. 我们有非托管代码,我们正在从托管代码中调用它。 这会阻止运行此代码。
    尝试运行这些命令并重新启动您的电脑

    cmd: netsh Winsock Reset

打开cmd.exe并运行命令“netshwinsock重置目录”

  1. 防病毒将非托管代码视为有害且限制运行此代码
    禁用防病毒软件,然后检查

Hi There are two possible reasons.

  1. We have un-managed code and we are calling it from managed code. that is preventing to run this code.
    try running these commands and restart your pc

    cmd: netsh winsock reset

open cmd.exe and run command "netsh winsock reset catalog"

  1. Anti-virus is considering un-managed code as harmful and restricting to run this code
    disable anti-virus and then check
空城之時有危險 2024-07-21 11:13:13

就我而言,当我在 IIS 服务器中为应用程序池设置“启用 32 位应用程序”=True 时,此问题已得到解决。

In my case this was fixed when I set up 'Enable 32 Bit applications'=True for Application pool in IIS server.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文