שתף באמצעות


Error : The object invoked has disconnected from its clients.

Question

Saturday, February 21, 2009 12:41 AM

I have created a simple program to navigate to a website when selected from a combobox. The navigation works fine but if I close the browser window and try to open a new window using the combobox I get the error:

System.Runtime.InteropServices.COMException (0x80010108): The object invoked has disconnected from its clients. (Exception from HRESULT: 0x80010108 (RPC_E_DISCONNECTED))
   at System.Runtime.InteropServices.ComTypes.IConnectionPoint.Unadvise(Int32 dwCookie)
   at SHDocVw.DWebBrowserEvents2_EventProvider.remove_DocumentComplete(DWebBrowserEvents2_DocumentCompleteEventHandler )
   at SHDocVw.InternetExplorerClass.remove_DocumentComplete(DWebBrowserEvents2_DocumentCompleteEventHandler )
   at detectIE.Form1.set_IE(InternetExplorer WithEventsValue)
   at detectIE.Form1.ComboBox1_SelectedIndexChanged(Object sender, EventArgs e) in C:\Documents and Settings\da315472\My Documents\Visual Studio 2008\Projects\detectIE\detectIE\Form1.vb:line 28
   at System.Windows.Forms.ComboBox.OnSelectedIndexChanged(EventArgs e)
   at System.Windows.Forms.ComboBox.WmReflectCommand(Message& m)
   at System.Windows.Forms.ComboBox.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

Here is the code:

Imports SHDocVw  
Public Class Form1  
Private WithEvents IE As InternetExplorer  
 
Private Sub IE_DocumentComplete(ByVal pDisp As Object, ByRef URL As Object) Handles IE.DocumentComplete  
MsgBox("nav complete")  
End Sub  
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged  
Dim myUrl  
myUrl = "blank" 
 
Select Case ComboBox1.Text  
Case "yahoo"  
myUrl = Http://www.yahoo.com  
Case "google"  
myUrl = "https://www.google.com" 
End Select  
 
IE = New SHDocVw.InternetExplorer  
IE.Visible = True 
IE.Navigate(myUrl)  
End Sub  
End Class  
 
 

Any idea why this is giving this error?

All replies (4)

Friday, February 27, 2009 8:49 AM ✅Answered | 1 vote

djacktx said:

I have created a simple program to navigate to a website when selected from a combobox. The navigation works fine but if I close the browser window and try to open a new window using the combobox I get the error:

System.Runtime.InteropServices.COMException (0x80010108): The object invoked has disconnected from its clients. (Exception from HRESULT: 0x80010108 (RPC_E_DISCONNECTED))

Thank you Toby for your friendly help.

Hi djacktx,

Welcome to MSDN forums!

I can repro this error message.

Here is the solution which works fine. Please take it a try.

Firstly Add Reference Microsoft Internet Controls (shdocvw.dll) to your project:

Project menu -> Add Reference -> COM tab -> Microsoft Internet Controls

Imports SHDocVw  

 

Public Class Form1  

 

    Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged  

        Dim myUrl As String 

        myUrl = "blank" 

        Select Case ComboBox1.Text  

            Case "yahoo" 

                myUrl = "Http://www.yahoo.com " 

            Case "google" 

                myUrl = "https://www.google.com" 

        End Select 

 

        Dim IE As InternetExplorer  

        IE = New SHDocVw.InternetExplorer  

        IE.Visible = True 

        IE.Navigate(myUrl)  

        AddHandler IE.DocumentComplete, AddressOf DocumentComplete  

    End Sub 

 

    Private Sub DocumentComplete(ByVal pDisp As Object, ByRef URL As Object)  

        MsgBox("nav complete")  

    End Sub 

 

End Class 

 

Best regards,
Martin Xie


Saturday, February 21, 2009 3:23 AM | 2 votes

Hello djacktx,

Your question made me curious and I started some research as i did not have an athock answer. Well, needless to say, I was not able to find an answer but I was able to modify your code and I do not get an error when running it.

The explorer opens and displays the pages with no errors being thrown.

Here is what I changed it to:

Dim IE As InternetExplorer
IE = Nothing
Dim myUrl As String
myUrl = "blank"
Select Case ComboBox1.Text
Case "yahoo"
myUrl = "Http://www.yahoo.com"
Case "google"
myUrl = "https://www.google.com"
End Select
IE = New InternetExplorer
IE.Navigate(myUrl)

Let me know if this solves your problem ( as I am really curious to find out :) ).

Happy coding!


Saturday, February 21, 2009 5:26 PM

 Toby.NY,

That fixed the error but now the DocumentComplete no longer works. What I need to do is to navigate to the site and once the site has loaded additional code will run. Since DocumentComplete never fires I can't run the additional code. Any ideas?

djacktx


Friday, February 27, 2009 7:06 PM

Martin,

That did the trick. It works just the way I need it to. Now I can continue adding my other code. Thanks so much for your help.

djacktx