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

  • Question

  • 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

    • Moved by Xavier Xie-MSFT Thursday, January 7, 2016 8:20 AM move to correct forum
    Wednesday, January 6, 2016 9:22 AM

All replies

  • Hi Prasannakumar3,

    WPF forum is aim to discuss and ask questions about how to use XAML technologies to productively create visually appealing and differentiating applications and to improve user experience.

    As your question is about extension of web browser. I will move this thread to Internet Explorer Extension Development forum for dedicated help.

    Thank you for your understanding.

    Best Regards,

    Xavier Eoro


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, January 7, 2016 8:20 AM
  • Hi Prasannakumar3,

    >>This works couple of times, but after sometime i get the following exception 

    Maybe Some frames contain PdF documents which hosted in a pdf reader activeX control. So we can't get the contentWindow property of it.

    Best Regards,
    Li Wang


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, January 8, 2016 1:41 AM
  • DocumentComplete is triggered for every frame, thus when you get the first DocumentComplete event after navigation, only one frame is ready for script injection. You should skip the event if the pDisp parameter does not contain the navigating frame. See https://support.microsoft.com/en-us/kb/180366 for details. 



    Visual C++ MVP

    Wednesday, January 20, 2016 6:27 PM
  • Hi Wang, 

    I am trying to load the CRM page, which doesn't have any pdf components in it. So, i guess that's not the issue.

    Thanks


    Friday, January 22, 2016 9:29 AM
  • Hi Sheng Jiang,

    Will try this out and update if it helped.

    Thanks


    Friday, January 22, 2016 9:30 AM
  • Hello all,

    I came across a very similar issue myself - I'm not sure whether this is going to help anybody *here* right now as this question is 2 years old, but I found a way around the problem.

    See:

    https://stackoverflow.com/questions/52964971/bizarre-case-sensitivity-issue-in-webbrowser-control-dom-access

    Wednesday, October 24, 2018 10:41 AM