C#WebBrowser控制系统.AccessViolationException

Aar*_*ith 30 .net c# browser exception

我有一个使用内置webbrowser控件的程序.在使用它的某个时刻,我不确定在什么时候,但它似乎是随机的,我得到以下错误:

System.AccessViolationException

FullText = System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
Run Code Online (Sandbox Code Playgroud)

有没有人有任何线索,为什么我会得到这个以及如何防止它?

Fil*_*ara 6

我们最近在几个客户的机器上遇到了类似的问题.在某些环境中,问题证明是MSHTML控件中的一个错误.该问题的常见症状似乎是jscript.dll库的注册被破坏.

可能有助于诊断是否存在相同问题的症状 - jscript.dll未在调试器中的模块中列出且未被进程加载; 崩溃的本机堆栈跟踪如下:

mshtml!CRootTracker::CollectGarbageInternal+0xd
mshtml!CDoc::ReduceMemoryPressureTask+0x29
mshtml!CStackPtrAry<unsigned long,12>::GetStackSize+0xb6
mshtml!GlobalWndProc+0x183
USER32!InternalCallWinProc+0x23
USER32!UserCallWinProcCheckWow+0x109
USER32!DispatchMessageWorker+0x3bc
USER32!DispatchMessageW+0xf
Run Code Online (Sandbox Code Playgroud)

解决方案是重新注册jscript.dll库,崩溃应该消失.

重新注册库的步骤如下(64位Windows的示例,否则只需要第一行):

C:\Windows\System32\regsvr32.exe C:\Windows\System32\jscript.dll
C:\Windows\SysWOW64\regsvr32.exe C:\Windows\SysWOW64\jscript.dll
Run Code Online (Sandbox Code Playgroud)

两个命令都必须"以管理员身份运行".


Jef*_*tes 3

我的直觉是,您在导航到文档之前就试图操纵该文档。在更改文档文本或 html 之前,尝试导航到“about:blank”。

如果您已经在执行导航,请注意导航是异步的,因此您需要监视浏览器的事件以检测导航何时完成。否则,您可以尝试在文档存在之前写入该文档。