1

I have a WPF application with a function to loop through open IE web pages (yes, we're still using IE) and scrape data from the HTML. Occasionally, users will get an error indicating "Public member 'name' on type WebBrowswer_V1 not found" followed by "Unable to cast COM object of type 'System._ComObject' to interface type 'mshtml.HTMLDocument'..." I am not finding too many answers as to why IE windows will occasionally be seen as "WebBrowser_V1" rather than "Internet Explorer". At this time, the only solution we've found is to shut down all instances of IE and restart the application, and, when that doesn't work, reboot the PC. I have been unable to replicate the error in debug. Can anyone assist in providing insight into how I might resolve this issue?

    Public Function loadKeyIDs() As DataTable
    Dim dt As New DataTable
    dt.Columns.Add("keyid")
    dt.Columns.Add("clientAcct")
    dt.Columns.Add("clientName")
    dt.Columns.Add("legalEntity")
    dt.Columns.Add("vendor")
    Dim shellWins As New SHDocVw.ShellWindows
    Dim explorer As SHDocVw.InternetExplorer
    Try
        For Each explorer In shellWins
            If isEformTracking(explorer) Then
                Dim x As HTMLDocument = explorer.Document
                Dim cm As HTMLInputElement = x.getElementsByName("grkeyid")(0)
                If Not cm Is Nothing Then
                    Dim y As eFormValues = collectClientInfoAbbreviated(x)
                    dt.Rows.Add(y.keyid, y.clientAcct, y.clientName, y.legalEntity, y.vendor)
                End If
            End If
        Next
    Catch ex As Exception
        Dim st As New StackTrace(True)
        st = New StackTrace(ex, True)
        Dim msg As String = ex.Message + " {Stack trace: " + st.GetFrame(0).GetFileLineNumber().ToString + "}"
        MsgBox("An error has occurred when trying to collect open eForm Tracking pages. Please relay this information to support: " & msg)
    Finally
        shellWins = Nothing
        explorer = Nothing
    End Try
    Return dt
End Function

Public Function isEformTracking(ie As SHDocVw.InternetExplorer) As Boolean
    Dim ret As Boolean = False
    If ie.Application.name <> "Internet Explorer" Then
        ret = False
        GoTo ExitSub
    End If

    If ie.ReadyState <> 4 Then
        ret = False
        GoTo ExitSub
    End If

    If Not ie.LocationURL Like "*eforms*" And Not ie.LocationURL Like "*qdcws0726*" And Not ie.LocationURL Like "*qdcws0738*" Then
        ret = False
        GoTo ExitSub
    End If

    If ie.LocationURL Like "*eforms*" Or ie.LocationURL Like "*qdcws0726*" And Not ie.LocationURL Like "*qdcws0738*" Then
        If ie.LocationURL Like "*sales*" Then
            ret = False
            GoTo ExitSub
        End If
    End If

    Dim doc As HTMLDocument = ie.Document
    Dim keyIDelem As HTMLInputElement = doc.getElementsByName("grkeyid")(0)

    If keyIDelem Is Nothing Then
        ret = False
        GoTo ExitSub
    End If

    If Len(keyIDelem.value) > 0 Then
        ret = True
        GoTo ExitSub
    End If
ExitSub:
    Return ret

End Function

enter image description here

enter image description here

Mike C
  • 21
  • 2
  • Generally, on which line you got this error? What happen if you try to restart the IE browser? If you had not checked then please try to check it. Also let us know, which version of the IE browser and which OS build you are using for making this test? It will help us to narrow down the issue. – Deepak-MSFT Jun 19 '20 at 05:38
  • Thank you Deepak. Indeed, restarting IE (IE 11) sometimes resolves the issue, but not always. We've had to resort to rebooting the PC to resolve, when that doesn't work. The users are are a mix of Windows 7 and Windows 10 users. The first error screenshot hits on the "ie.Application.Name" in the function. Upon removing that, it will still hit the second error if the window is seen as WebBrowser_V1. That one hits at the Dim doc As HTMLDocument = ie.Document in the function. I assume because HTML document isn't an interface for WebBrowser_V1. – Mike C Jun 19 '20 at 15:38
  • Does this issue occur after using this code for a long time? I suggest trying to check for the latest Windows updates and see whether it helps to fix this issue. check whether any other app on your machine using web browser control. – Deepak-MSFT Jun 24 '20 at 05:51
  • It appears to be completely random. Two users received the error after first installing the application whereas others have reported it happening at random. I'll see if we can narrow it down to any other applications using the web browser control at the time of error. – Mike C Jun 29 '20 at 19:38
  • Try to handle this specific error or try to check the ie.Application type in your code and try to move to the next step in the loop if you get WebBrowswer_V1. See if it helps to avoid this issue. – Deepak-MSFT Jun 30 '20 at 05:50

0 Answers0