locked
System.ObjectDisposedException/mscorlib.pdb not loaded/Stop at Exception: MoveNext. An exception was caught by the debugger RRS feed

  • Question

  • User-1964148663 posted

    This error mostly occuring when i click btnSendhelloObject_Click when i click it number of time then i get following errors in break mode. To be honest i have no idea what could be cause of this whether some bad code implementation somwhere or bug itself. Hope anyone of you could take a look on that.

    mscorlib.pdb not loaded
    
        Event
            Activated   Event   Time    Duration    Thread
                Stop at Exception: MoveNext. An exception was caught by the debugger, and user settings indicate that a break should occur. 9.87s   9,876ms [9128] <No Name>

    Tasks:

        Not Flagged     0           
        Not Flagged     34  Scheduled   [Scheduled and waiting to run]  Task.ContinueWith: <OnStart>b__16_0
        Not Flagged     49  Active      Async: <ProcessWebSocketRequestAsync>d__25
        Not Flagged     2895    Scheduled   [Scheduled and waiting to run]  Async: VB$StateMachine_10_btnSendhelloObject_Click
        Not Flagged     2908    Scheduled   [Scheduled and waiting to run]  Async: <ReadAsync>d__21
        Not Flagged     2911    Awaiting        Async: <Process>d__19
        Not Flagged     2913    Awaiting        Async: <ReceiveAsyncCore>d__45
        Not Flagged     2914    Scheduled   [Scheduled and waiting to run]  Async: <ReadMessageAsync>d__3
    

    This is my code

       Imports System.Drawing
        Imports System.Net
        Imports System.Threading
        Imports Bal
        Imports DevComponents.DotNetBar
        Imports DevComponents.DotNetBar.Controls
        Imports Microsoft.AspNet.SignalR.Client
        Public Class Form1
    
            Private thisLock As New Object
    
            Private Connection As HubConnection
            Private Proxy As IHubProxy
    
            Private Async Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
                Try
                    Await InitializeConnection()
                Catch ex As Exception
                    SyncLock thisLock
                        msg_listview.Items.Add(New ListBoxItem With {.BackColors = New Color() {Color.Red}, .TextColor = Color.White, .Text = "Form1_Load: " + ex.ToString()})
                    End SyncLock
                End Try
            End Sub
    
            Async Function InitializeConnection() As Task
                If Connection IsNot Nothing Then
                    Connection.Dispose()
                End If
    
                Connection = New HubConnection("http://localhost:4848")
                ServicePointManager.DefaultConnectionLimit = 10
    
                Proxy = Connection.CreateHubProxy("Main")
    
                AddHandler Connection.Closed, AddressOf OnDisconnected
                AddHandler Connection.Reconnecting, AddressOf OnReconnecting
                AddHandler Connection.Reconnected, AddressOf OnReconnected
    
                'Proxy.[On](Of String, String)("addMessage", Sub(name, message) Console.Write("Recieved addMessage: " + name + ": " + message + vbLf))
                Proxy.[On](Of String)("heartbeat", Sub()
                                                       SyncLock thisLock
                                                           msg_listview.Items.Add("Recieved hearbeat")
                                                       End SyncLock
                                                   End Sub)
                Proxy.[On](Of HelloModel)("sendHelloObject",
                                          Sub(hello)
                                              SyncLock thisLock
                                                  msg_listview.Items.Add("Recieved sendHelloObject: Molly: " + hello.Molly + " Age: " + hello.Age.ToString())
                                              End SyncLock
                                          End Sub)
    
                SyncLock thisLock
                    msg_listview.Items.Add(New ListBoxItem With {.BackColors = New Color() {Color.Yellow}, .TextColor = Color.Black, .Text = "TRYING TO CONNECT"})
                End SyncLock
    
                Await ConnectWithRetry()
    
            End Function
    
            Private Async Function ConnectWithRetry() As Task
                ' If this fails, the 'Closed' event (OnDisconnected) is fired
                Try
                    Await Connection.Start()
    
                    SyncLock thisLock
                        msg_listview.Items.Add(New ListBoxItem With {.BackColors = New Color() {Color.Green}, .TextColor = Color.White, .Text = "CONNECTED"})
                    End SyncLock
                Catch ex As Exception
                    SyncLock thisLock
                        msg_listview.Items.Add(New ListBoxItem With {.BackColors = New Color() {Color.Red}, .TextColor = Color.White, .Text = "ConnectWithRetry: " + ex.ToString()})
                    End SyncLock
                End Try
            End Function
    
        #Region "OnDisconnected"
            Private Async Sub OnDisconnected()
                'msg_listview.Invoke(Sub()
                SyncLock thisLock
                    msg_listview.Items.Add(New ListBoxItem With {.BackColors = New Color() {Color.Black}, .TextColor = Color.White, .Text = "CLOSED"})
                End SyncLock
                ' End Sub)
                ' Small delay before retrying connection
                Thread.Sleep(5000)
                ' Need to recreate connection
                Await InitializeConnection()
            End Sub
        #End Region
    
        #Region "OnReconnecting"
            Private Sub OnReconnecting()
                SyncLock thisLock
                    msg_listview.Items.Add(New ListBoxItem With {.BackColors = New Color() {Color.Gray}, .TextColor = Color.White, .Text = "RECONNECTING"})
                End SyncLock
            End Sub
        #End Region
    
        #Region "OnReconnected"
            Private Sub OnReconnected()
                SyncLock thisLock
                    msg_listview.Items.Add(New ListBoxItem With {.BackColors = New Color() {Color.Green}, .TextColor = Color.White, .Text = "RECONNECTED"})
                End SyncLock
            End Sub
        #End Region
    
        #Region "btnSendhelloObject_Click"
            Private Async Sub btnSendhelloObject_Click(sender As Object, e As EventArgs) Handles btnSendhelloObject.Click
                Dim hello As New HelloModel() With {
                              .Age = 10,
                              .Molly = "clientMessage"
                          }
                Try
                    Dim foo As HelloModel = Await Proxy.Invoke(Of HelloModel)("SendHelloObject", hello)
                    SyncLock thisLock
                        msg_listview.Items.Add(New ListBoxItem With {.BackColors = New Color() {Color.White}, .TextColor = Color.Black, .Text = "Client sendHelloObject sent to --> server"})
                        msg_listview.Items.Add(New ListBoxItem With {.BackColors = New Color() {Color.White}, .TextColor = Color.Black, .Text = "Response: " + hello.Molly.ToString()})
                    End SyncLock
                Catch ex As Exception
                    'msgbox (ex.ToString())
                    SyncLock thisLock
                        msg_listview.Items.Add(New ListBoxItem With {.BackColors = New Color() {Color.Red}, .TextColor = Color.White, .Text = "btnSendhelloObject_Click: " + ex.ToString()})
                    End SyncLock
                End Try
            End Sub
        #End Region
    
        End Class
    
     
    Wednesday, October 26, 2016 11:37 AM

All replies

  • User-707554951 posted

    Hi  JimmyJimm,

    An ObjectDisposedException is thrown when you try to access a member of an object that implements the IDisposable interface, and that object has been disposed. Typically, this exception is caused by one of the following conditions:

    You've called an object's Dispose method, and you’re trying to access an instance member that gets or sets the object's state

    So, Make sure you have not released a resource before attempting to use it.

    For example, if attempting to manipulate a stream, make sure it has not been previously closed.

    Best regards

    Cathy

    Thursday, October 27, 2016 6:22 AM