Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

WPF Webbrowser control throwing System.NotSupportedException: Exception from HRESULT: 0x800A01B6

$
0
0

I am using a WPF webbrowser control placed inside usercontrol and this usercontrol is inside avalondock, and have implemented the webbrowser event sink as below with other methods as well. I am trying to execute javascript function within the page and any frames available. This works couple of times, but after sometime i get the following exception 

System.NotSupportedException: Exception from HRESULT: 0x800A01B6
   at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, object target, Int32[] aWrapperTypes, MessageData& msgData)
   at mshtml.DispHTMLFrameElement.get_ContentWindow()
   at WebBrowserEventSink.DocumentComplete(Object pDisp, Object& URL)

exception in the DocumentComplete method at the following line. 

                      if ((frm as HTMLFrameElement).contentWindow != null)

[ComVisible(true)]
[ClassInterface(ClassInterfaceType.None)]
[ComDefaultInterface(typeof(SHDocVw.DWebBrowserEvents2))]
public class WebBrowserEventSink : SHDocVw.DWebBrowserEvents2

{

         

 public void DocumentComplete(object pDisp, ref object URL)
    {

        try
        {

            mshtml.IHTMLDocument2 doc = _webBrowser.Document as mshtml.IHTMLDocument2;

            if (doc != null && doc.parentWindow != null)
            {
                doc.parentWindow.execScript("handlePopupBlockerError = function (url) { }", "javascript");

                IHTMLElementCollection frames = (IHTMLElementCollection)((doc) as HTMLDocument).getElementsByTagName("iframe");

                if (frames != null)
                {
                    foreach (IHTMLElement2 frm in frames)
                    {   
                        if ((frm is IHTMLElement2) && (frm is HTMLFrameElement) && (frm as HTMLFrameElement) != null)
                        {
                            try
                            {
                      if ((frm as HTMLFrameElement).contentWindow != null)
                                {
                                    try
                                    {
                                        (frm as HTMLFrameElement).contentWindow.execScript("handlePopupBlockerError = function (url) {}", "javascript");
                                    }
                                    catch (NotSupportedException ntsupportException)
                                    {
                                        Log.Error(functionName + ntsupportException.Message);
                                        Log.Error(functionName, ntsupportException);
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                                Log.Error(functionName + ex.Message);
                                Log.Error(functionName, ex);
                            }
                        }
                    }
                }
            }
            else
            {
                Log.Warn(functionName + string.Format("doc / parentwindow was null"));
            }
}
catch (Exception Ex)
        {
            Log.Error(functionName + Ex.Message);
            Log.Error(functionName, Ex);
        }
    }


Any help is greatly appreciated.

Thanks

Prasanna


Viewing all articles
Browse latest Browse all 18858

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>