本文介绍了自定义WebBrowser(winforms)代码的致命错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 限时删除!! 在CustomWebBrowser(winforms)代码上产生致命异常。 运行时遇到致命错误。错误的地址在0x6c9a60c6,在线程0xf94。错误代码为0xc0000005。此错误可能是CLR中的错误或用户代码的不安全或不可验证部分中的错误。这个bug的常见来源包括COM-interop或PInvoke的用户封送错误,这可能会破坏堆栈。 .Net Framework 4.0 安装 .Net Framework 4.5 ,但不适用于 //构造函数 public AutoCompleteWebBrowserSite(WebBrowser host): base(host) { //获取CCW object for this _unkOuter = Marshal.GetIUnknownForObject(this); Marshal.AddRef(_unkOuter); try { //用帮助器聚合CCW对象内部对象 _inner = new AutoCompleteHelper(this); _unkInnerAggregated = Marshal.CreateAggregatedObject(_unkOuter,_inner); //获取私有WebBrowserSite COM接口 try { _baseIDocHostUiHandler =(WebBrowserNativeMethods.IDocHostUIHandler)Marshal.GetTypedObjectForIUnknown(_unkInnerAggregated,typeof(WebBrowserNativeMethods.IDocHostUIHandler)); } catch(Exception)} finally { Marshal.Release(_unkOuter); } } 异常抛出在 _baseIDocHostUiHandler =(WebBrowserNativeMethods.IDocHostUIHandler)Marshal.GetTypedObjectForIUnknown(_unkInnerAggregated,typeof(WebBrowserNativeMethods.IDocHostUIHandler)); 也尝试了通过在app.config文件中禁用gcConcurrent禁用并发垃圾回收 $ b $ 解决方案基本上需要从构造函数中删除所有的代码主要是_baseIDocHostUiHandler) 然后在WebBrowserSite实现中,尝试返回每个方法的默认实现值。 private const int DefaultImpVal = unchecked((int)0x80004001) #region IDocHostUIHandler int WebBrowserNativeMethods.IDocHostUIHandler.ShowContextMenu(int dwId,ref WebBrowserNativeMethods .Point pt,IntPtr pcmdtReserved,IntPtr pdispReserved) { return DefaultImpVal; } int WebBrowserNativeMethods.IDocHostUIHandler.ShowUI(int dwId,IntPtr activeObject,IntPtr commandTarget,IntPtr frame,IntPtr doc) { return DefaultImpVal; } 。 Getting a fatal exception on the CustomWebBrowser (winforms) code."The runtime has encountered a fatal error. The address of the error was at 0x6c9a60c6, on thread 0xf94. The error code is 0xc0000005. This error may be a bug in the CLR or in the unsafe or non-verifiable portions of user code. Common sources of this bug include user marshaling errors for COM-interop or PInvoke, which may corrupt the stack."This is working fine on machines that has .Net Framework 4.5 installed, however not in machines with .Net framework 4.0// constructor public AutoCompleteWebBrowserSite(WebBrowser host) : base(host) { // get the CCW object for this _unkOuter = Marshal.GetIUnknownForObject(this); Marshal.AddRef(_unkOuter); try { // aggregate the CCW object with the helper Inner object _inner = new AutoCompleteHelper(this); _unkInnerAggregated = Marshal.CreateAggregatedObject(_unkOuter, _inner); // obtain private WebBrowserSite COM interfaces try { _baseIDocHostUiHandler = (WebBrowserNativeMethods.IDocHostUIHandler) Marshal.GetTypedObjectForIUnknown(_unkInnerAggregated,typeof (WebBrowserNativeMethods.IDocHostUIHandler)); } catch(Exception) } finally { Marshal.Release(_unkOuter); } }The exception was thrown at _baseIDocHostUiHandler = (WebBrowserNativeMethods.IDocHostUIHandler)Marshal.GetTypedObjectForIUnknown(_unkInnerAggregated,typeof (WebBrowserNativeMethods.IDocHostUIHandler));Also tried disabling concurrent garbage collection by disabling gcConcurrent in the app.config fileAny help would be really appreciated. 解决方案 Basically need to remove all the code from constructor (mainly _baseIDocHostUiHandler)And then in the WebBrowserSite implementation, try return the default implementation value for each of the methods. private const int DefaultImpVal = unchecked((int)0x80004001) #region IDocHostUIHandler int WebBrowserNativeMethods.IDocHostUIHandler.ShowContextMenu(int dwId, ref WebBrowserNativeMethods.Point pt, IntPtr pcmdtReserved, IntPtr pdispReserved) { return DefaultImpVal ; }int WebBrowserNativeMethods.IDocHostUIHandler.ShowUI(int dwId, IntPtr activeObject, IntPtr commandTarget, IntPtr frame, IntPtr doc) { return DefaultImpVal; }similarly for other methods. 这篇关于自定义WebBrowser(winforms)代码的致命错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 1403页,肝出来的..
09-08 15:02