none
Error : Managed Debugging Assistant 'CallbackOnCollectedDelegate' RRS feed

  • Question

  • Hi Everybody,

    I used this snippet to load customer name to a text box 

     Sub autocomplete()
            conn = New OleDbConnection(cs)
            conn.Open()
    
            Dim cmd As New OleDbCommand("SELECT B_name FROM Customer", conn)
            Dim ds As New DataSet
            Dim da As New OleDbDataAdapter(cmd)
            da.Fill(ds, "My List") 
    
            Dim col As New AutoCompleteStringCollection
            Dim i As Integer
    
            For i = 0 To ds.Tables(0).Rows.Count - 1
                col.Add(ds.Tables(0).Rows(i)("B_name").ToString())
            Next
    
            B_name.AutoCompleteSource = AutoCompleteSource.CustomSource
            B_name.AutoCompleteCustomSource = col
            B_name.AutoCompleteMode = AutoCompleteMode.Suggest
    
            conn.Close()
            
        End Sub

    But when i used the same code for Address in the same form an error occurs called 'CallbackOnCollectedDelegate'

     Sub autocompleteAddress()
            Using conn = New OleDbConnection(cs)
                conn.Open()
    
                Using cmd As New OleDbCommand
                    cmd.Connection = conn
                    cmd.CommandText = "SELECT B_Address FROM Customer"
    
                    Using ds As New DataSet, da As New OleDbDataAdapter(cmd)
                        da.Fill(ds, "List")  
    
                        Dim acsc As New AutoCompleteStringCollection
                        Dim i As Integer
    
                        For i = 0 To ds.Tables(0).Rows.Count - 1
                            acsc.Add(ds.Tables(0).Rows(i)("B_Address").ToString())
                        Next
    
                        B_Address.AutoCompleteSource = AutoCompleteSource.CustomSource
                        B_Address.AutoCompleteCustomSource = acsc
                        B_Address.AutoCompleteMode = AutoCompleteMode.Suggest
    
                    End Using
                End Using
            End Using
    
        End Sub

    I used this snippets as follows 

        Private Sub Panel1_Enter(sender As Object, e As EventArgs) Handles Panel1.Enter
            autocomplete()
        End Sub
    
    
        Private Sub B_name_Validating(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles B_name.Validating
            autocompleteAddress()
        End Sub

    The full message says :

    Additional information: A callback was made on a garbage collected delegate of type 'System.Windows.Forms!System.Windows.Forms.NativeMethods+WndProc::Invoke'. This may cause application crashes, corruption and data loss. When passing delegates to unmanaged code, they must be kept alive by the managed application until it is guaranteed that they will never be called.

    I searched here and i found a same problem with combo boxes ..... Only solution came to my mind that i delete one of the both subrotines , and change the text box of address to combo box , but i think there is another solution to this problem ......

      

    Any suggestions ... 

    Thanks in advance ......


    Regards From Amr_Aly

    Saturday, December 15, 2018 9:45 AM

All replies

  • OK ,  when i used the code of loading name and address as follows

    Private Sub B_name_Validating(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles B_name.Validating
            autocompleteAddress()
        End Sub
    
        Private Sub txtCustomerNo_Validating(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles txtCustomerNo.Validating
            autocomplete()
        End Sub

    the error disappeared (I'm still investigating it but it seems to be well)... I removed the snippet from (Panel1_Enter event) and put it in a (txtCustomerNo_Validating event) 

    The question here is why this error appears and will this error appear in the future ? 

    Thanks in advance ..........

      

    Regards From Amr_Aly

    Saturday, December 15, 2018 10:09 AM
  • Unless I'm missing something, why don't you load the data on form load rather than in one of the events you are using now? See my code sample on working with auto complete.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Saturday, December 15, 2018 11:30 AM
    Moderator
  • Unless I'm missing something, why don't you load the data on form load rather than in one of the events you are using now? See my code sample on working with auto complete.

    Thanks Karen,

    Yes i'm not use form load to perform this action because the form takes time to load and it's obvious to anyone ,So  i have to avoid this issue by using another events like 'Validating event' or whatever

    if i'm wrong please explain to me how we can perform it or how we can avoid lateness of form load ?  

      


    Regards From Amr_Aly


    • Edited by Amr_Aly Sunday, December 16, 2018 8:40 PM
    Sunday, December 16, 2018 10:00 AM