错误:C#尝试读取或写入受保护的内存 [英] Error: C# Attempted to read or write protected memory

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

问题描述

由于难以纠正此错误,该应用程序已在4台不同的计算机上进行了测试,并且在其中3台计算机上均可正常运行,但是一台Vista PC在尝试打开通过WebBrower1的页面槽时出现此错误

im having a hard time correcting this bug, the app is tested on 4 diffrent machines and works fine on 3 of them but one vista PC gives this error when trying to open a page trough WebBrower1

解决这个问题的任何帮助对我很有帮助。

anyhelp resolving this wold be very helpful to me.

System.AccessViolationException occurred
Message="Attempted to read or write protected memory. This is often an indication that other memory is corrupt."
Source="System.Windows.Forms"
StackTrace:
   ved System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
   ved System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
   ved System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
   ved System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
   ved System.Windows.Forms.Application.Run(Form mainForm)
   ved Dispatcher_Tool.Program.Main() i C:\Users\norah\Downloads\Kopi av Dispacher Tool_utvikling\Dispacher Tool\Program.cs:linje 18
InnerException: 

更新:

我发现我的代码不是问题,我尝试创建一个测试仅带webBrowser和直接URL的新表单网页。

i have found out that that my code is not the issue, i tryed creating a test new form with only a webBrowser and the direct URL for opening the Web page.

网页启动,然后网页上的脚本打开了一个辅助页面,该页面似乎试图将我的webBrowser1重定向到脚本告诉它的页面

the web page starts, then the script on the web page opens a secondary page that seems to try to redirect my webBrowser1 to the page the script tells it too.

如果我设置了webBrowser1.AllowNavigation = False,我没有崩溃,所以当脚本尝试在webBrowser1中更新时,似乎发生了错误,有人知道了如何要解决此问题?

if i set webBrowser1.AllowNavigation = False i dont get the Crash so the error seems to happen when teh script trys to update in webBrowser1, anyone got a clue how to work around this?

推荐答案

这是Vista问题,发生了什么事,我的应用程序打开了一个运行Java的网页小程序,可打开运行ActiveX应用程序/脚本的外部IE网页。当ActiveX脚本尝试更新回C#应用程序的内存时,Vista中的DEP数据执行保护将该操作标记为敌对/病毒,并以System.AccessViolationException结束该程序:尝试读取或写入受保护的内存。这通常表明其他内存已损坏。

It was a Vista Issue, what happens was that my App opens a web page that runs a java applet that opens a external IE webpage that runs a ActiveX app/script. When the ActiveX script tryes to update back in to the memory of the C# app the DEP "Data Execution Prevention" in Vista flags this operation as Hostile/virus and ends the program with the System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt."

我的解决方法是在Vista中打开DEP,并使用以下行
bcdedit.exe /设置{current} nx AlwaysOff

My fix for this was to turn of DEP in Vista with this line "bcdedit.exe /set {current} nx AlwaysOff"

并重新启动计算机。

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

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