内存改正错误... [英] Memmory correpted Error...

查看:86
本文介绍了内存改正错误...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友,
.我目前正在使用c#作为语言和.net 3.5的Windows应用程序中工作.该应用程序是MDI接口.
在调用子窗体时出现如下错误(显示此异常的代码是frminstance..MdiParent = this;)

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

奇怪的是,此异常仅以一种子形式出现.所有其他孩子正确打开.我进行了搜索,并找到了一些DEP解决方案.但是并没有解决我的问题.谁能说出原因?

环境:

Windows XP sp2
VS 2008

子窗体直接调用,我的意思是不在其mdi中对其进行调用在职的.从MDI表单调用时仅显示错误

解决方案

您好akhilrajau,

欢迎来到MSDN论坛!

我想为您提供以下建议:

在大多数情况下,纯.NET代码不会出现这种错误. CLR旨在通过开发人员代码来避免这些情况.但是,当您超出纯托管代码的范围时,导致此问题的原因是无效的指针.当您传递指向API的指针时,可能会发生这种情况.如果指针为空(地址为0),则几乎总是会收到此错误(假定非托管代码不会首先崩溃).如果指针包含的地址值超出了为应用程序分配的内存范围,或在保留给操作系统使用的范围内,那么您还将收到错误消息.另外,您可以映射具有不同访问级别的内存(实际上,作为.NET程序员,您通常不这样做,但是其他一些非托管代码也可以).如果您的进程没有读取"消息,访问该映射的内存范围,您还会收到此错误.

简而言之,大多数情况下,您的代码尝试使用非托管代码是一个错误(通过值而不是ref传递某些东西,或者传递空指针,或者传递某种空指针,等等)达到这种效果),或者这是第三方托管库中的错误(甚至可能是驱动程序,具体取决于我们在此处与哪种类型的代码进行交互).

有关更多信息,请查看以下线程:
http://forums.msdn.microsoft .com/zh-CN/clr/thread/a6e81c9b-ff94-4bcb-ba28-33e226291044/


在Visual Studio 2005/2008中,您可以考虑设置调试器按以下步骤操作:
工具"菜单->选项->调试->一般->取消选中选项在模块加载时禁止JIT优化(仅限托管).


将其从VB General论坛移至C#General论坛以获取更好的响应.

此致,
谢马丁(Martin Xie)


hi friends,
  I am currently working in a windows application using c# as language and .net 3.5. The application is MDI interface.
I got the error when call the child form as follows(The code showing this exception is frminstance..MdiParent = this;)

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

The strange is this exception came only in one child form. All other child opening correctly. I searched and got some solution as DEP. But didn't solved my issue. Can anyone tell the reason?.

Environment:
  
   Windows XP sp2
   VS 2008

Edit:  The child form call directly, i mean not with in mdi its working. When call from the MDI form only showing the error

解决方案

Hi akhilrajau,

Welcome to MSDN forums!

I would like to provide you the following suggestions:

Most of the time you will not see this kind of an error with purely .NET code. The CLR was designed to avoid these situations with developer code. However, when you go beyond purely managed code, an invalid pointer is what causes this problem. This can happen when you pass a pointer to an API. If the pointer is null (the address is 0), you will almost always get this error (assuming the unmanaged code doesn't crash first). If the pointer contains an address value that is outside the allocated memory range for the app, or is in the range reserved for OS usage, then you will also get the error. Additionally, you can map memory with different access levels (actually, as a .NET programmer, you usually don't, but some other unmanaged code might). If your process doesn't have "read" access to that mapped memory range, you'll also get this error.

In short, most of the time it's a bug with your code trying to use unmanaged code (passing something by value instead of by ref, or passing a null pointer, or something to that effect), or it's a bug in a 3rd party unmanaged library (even possibly a driver depending on what kind of code we're interacting with here).

For further information, please take a look at the following thread:
http://forums.msdn.microsoft.com/en-US/clr/thread/a6e81c9b-ff94-4bcb-ba28-33e226291044/

In Visual Studio 2005/2008, you can consider setting the Debugger as the following steps:
Tools menu -> Options -> Debugging -> General -> Uncheck option "Suppress JIT optimization on module load (Managed Only).

 
Move it from VB General forum to C# General forum for better responses.

Best regards,
Martin Xie


这篇关于内存改正错误...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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