尝试读取或写入受保护的内存!! [英] attempted to read or write protected memory!!

查看:187
本文介绍了尝试读取或写入受保护的内存!!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

" Unhandled Exception:System.AccessViolationException : 尝试读取或写入受保护的内存。这通常表明其他记忆是
腐败"

这种问题一直都在发生。我正在使用Visual Basic 2010并使用.Net 4

我已经尝试过以下设置选项,但它仍显示相同的警告!!

工具菜单 - >选项 - >调试 - >一般 - >取消选中此选项"抑制模块加载时的JIT优化"

您是否会建议超越此问题!

Will you give me a suggestion to surpass this issue!

推荐答案

如果您只使用托管代码,通常不会发生此错误。您设法破坏内存的事实表明,在您的程序中的某个时刻,您正在调用一些非托管代码,并且该代码中存在错误。如果您使用[DllImport]调用外部DLL并且extern声明错误或者您正在使用错误的参数,则可能会发生
。如果调用COM对象并且COM或其类型库中存在错误,也会发生这种情况。此外,如果您使用
第三方库或组件本身包含非托管代码,并且该代码中存在错误。哦,还有一件事:如果您使用多线程代码并从与创建UI的
线程不同的线程操作UI,您也可能损坏内存。

Normally this error would never happen if you were only using Managed Code. The fact that you have managed to corrupt the memory indicates that at some point in your program you are calling some unmanaged code, and there is a mistake in that code. This could happen if you are calling an external DLL using [DllImport] and the extern declaration is wrong or you are pasing the wrong parameters. It can also happen if you invoke a COM object and there is a mistake in the COM or its type library. And also if you use a third-party library or component that itself contains unmanaged code and there is a mistake in that code. Oh, and another thing: you can also corrupt memory if you use multithreaded code and manipulate the UI from a thread that is different from the thread that created the UI.

解决方案是隔离产生上述问题之一的代码的特定部分,然后修复其中的任何错误。没有"神奇"的东西。补救措施,例如更改Visual Studo中的选项。

The solution is to isolate the specific part of the code that produces one of the above problems and then fix whatever is wrong in it. There is no "magical" remedy such as changing an option in Visual Studo.


这篇关于尝试读取或写入受保护的内存!!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆