Click here to Skip to main content
15,886,519 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
When closing a data bound mdi child form I get an unhandled exception error.

It only happens at run time, not design time.

I don't understand the stack trace (but I never do)

Any help would be greatly appreciated ! ! !

Unhandled exception at 11/4/2014 1:46:07 PM

e.Exception.Message = Cannot bind to the property or column RevAcctID on the DataSource.
Parameter name: dataMember

e.Exception.StackTrace =    at System.Windows.Forms.BindToObject.CheckBinding()
   at System.Windows.Forms.Binding.SetListManager(BindingManagerBase bindingManagerBase)
   at System.Windows.Forms.ListManagerBindingsCollection.AddCore(Binding dataBinding)
   at System.Windows.Forms.BindingsCollection.Add(Binding binding)
   at System.Windows.Forms.BindingContext.UpdateBinding(BindingContext newBindingContext, Binding binding)
   at System.Windows.Forms.Control.UpdateBindings()
   at System.Windows.Forms.Control.OnBindingContextChanged(EventArgs e)
   at System.Windows.Forms.ListControl.OnBindingContextChanged(EventArgs e)
   at System.Windows.Forms.Control.CreateControl()
   at System.Windows.Forms.Control.RecreateHandleCore()
   at System.Windows.Forms.ComboBox.RecreateHandleCore()
   at System.Windows.Forms.ComboBox.SetAutoComplete(Boolean reset, Boolean recreate)
   at System.Windows.Forms.ComboBox.OnDataSourceChanged(EventArgs e)
   at System.Windows.Forms.ListControl.SetDataConnection(Object newDataSource, BindingMemberInfo newDisplayMember, Boolean force)
   at System.Windows.Forms.ListControl.DataSourceDisposed(Object sender, EventArgs e)
   at System.ComponentModel.Component.Dispose(Boolean disposing)
   at System.Windows.Forms.BindingSource.Dispose(Boolean disposing)
   at System.ComponentModel.Component.Dispose()
   at System.ComponentModel.Container.Dispose(Boolean disposing)
   at System.ComponentModel.Container.Dispose()
   at TOM.frmItemDetail.Dispose(Boolean disposing)
   at System.ComponentModel.Component.Dispose()
   at System.Windows.Forms.Form.WmClose(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)

e.Exception.Source = System.Windows.Forms




Iterating through the Stack Frames...
(Filename= Line 0) Getmethod.module=System.Windows.Forms.dll Getmethod=System.Windows.Forms.BindToObject.CheckBinding
(Filename= Line 0) Getmethod.module=System.Windows.Forms.dll Getmethod=System.Windows.Forms.Binding.SetListManager
(Filename= Line 0) Getmethod.module=System.Windows.Forms.dll Getmethod=System.Windows.Forms.ListManagerBindingsCollection.AddCore
(Filename= Line 0) Getmethod.module=System.Windows.Forms.dll Getmethod=System.Windows.Forms.BindingsCollection.Add
(Filename= Line 0) Getmethod.module=System.Windows.Forms.dll Getmethod=System.Windows.Forms.BindingContext.UpdateBinding
(Filename= Line 0) Getmethod.module=System.Windows.Forms.dll Getmethod=System.Windows.Forms.Control.UpdateBindings
(Filename= Line 0) Getmethod.module=System.Windows.Forms.dll Getmethod=System.Windows.Forms.Control.OnBindingContextChanged
(Filename= Line 0) Getmethod.module=System.Windows.Forms.dll Getmethod=System.Windows.Forms.ListControl.OnBindingContextChanged
(Filename= Line 0) Getmethod.module=System.Windows.Forms.dll Getmethod=System.Windows.Forms.Control.CreateControl
(Filename= Line 0) Getmethod.module=System.Windows.Forms.dll Getmethod=System.Windows.Forms.Control.RecreateHandleCore
(Filename= Line 0) Getmethod.module=System.Windows.Forms.dll Getmethod=System.Windows.Forms.ComboBox.RecreateHandleCore
(Filename= Line 0) Getmethod.module=System.Windows.Forms.dll Getmethod=System.Windows.Forms.ComboBox.SetAutoComplete
(Filename= Line 0) Getmethod.module=System.Windows.Forms.dll Getmethod=System.Windows.Forms.ComboBox.OnDataSourceChanged
(Filename= Line 0) Getmethod.module=System.Windows.Forms.dll Getmethod=System.Windows.Forms.ListControl.SetDataConnection
(Filename= Line 0) Getmethod.module=System.Windows.Forms.dll Getmethod=System.Windows.Forms.ListControl.DataSourceDisposed
(Filename= Line 0) Getmethod.module=System.dll Getmethod=System.ComponentModel.Component.Dispose
(Filename= Line 0) Getmethod.module=System.Windows.Forms.dll Getmethod=System.Windows.Forms.BindingSource.Dispose
(Filename= Line 0) Getmethod.module=System.dll Getmethod=System.ComponentModel.Component.Dispose
(Filename= Line 0) Getmethod.module=System.dll Getmethod=System.ComponentModel.Container.Dispose
(Filename= Line 0) Getmethod.module=System.dll Getmethod=System.ComponentModel.Container.Dispose
(Filename= Line 0) Getmethod.module=TOM.exe Getmethod=TOM.frmItemDetail.Dispose
(Filename= Line 0) Getmethod.module=System.dll Getmethod=System.ComponentModel.Component.Dispose
(Filename= Line 0) Getmethod.module=System.Windows.Forms.dll Getmethod=System.Windows.Forms.Form.WmClose
(Filename= Line 0) Getmethod.module=System.Windows.Forms.dll Getmethod=System.Windows.Forms.Control+ControlNativeWindow.WndProc
(Filename= Line 0) Getmethod.module=System.Windows.Forms.dll Getmethod=System.Windows.Forms.NativeWindow.Callback


P.S. I used the below code to gather the above quoted exception details


VB
Dim Msg1 As String = "Unhandled exception at " & Now.ToString & vbCrLf & vbCrLf
Msg1 += "e.Exception.Message = " & e.Exception.Message.ToString & vbCrLf & vbCrLf
Msg1 += "e.Exception.StackTrace = " & e.Exception.StackTrace & vbCrLf & vbCrLf
Msg1 += "e.Exception.Source = " & e.Exception.Source & vbCrLf & vbCrLf & vbCrLf
Dim MsgFull As String = Msg1 & "Do you wish to attempt to continue?" & vbCrLf & vbCrLf

Dim reply As MsgBoxResult = MsgBox(MsgFull, MsgBoxStyle.OkCancel, "Details logged to C:\tEMP\Unhandled.txt and C:\tEMP\Unhandled-Detailed.txt")
If reply = MsgBoxResult.Ok Then e.ExitApplication = False

Dim sw As New IO.StreamWriter("C:\tEMP\Unhandled.txt", True)
sw.Write(Msg1 & vbCrLf & vbCrLf)
sw.Close()

sw = New IO.StreamWriter("C:\tEMP\Unhandled-Detailed.txt", True)
sw.Write(Msg1 & vbCrLf & vbCrLf)
Dim st As StackTrace = New StackTrace(e.Exception, True)
sw.WriteLine("Iterating through the Stack Frames...")
For Each sf As StackFrame In st.GetFrames
    sw.Write("(Filename=" & sf.GetFileName & " Line " & sf.GetFileLineNumber() & ") Getmethod.module=" & sf.GetMethod.Module.ToString & " Getmethod=" & sf.GetMethod.DeclaringType.FullName.ToString & "." & sf.GetMethod.Name.ToString & vbCrLf)
Next
sw.Write(vbCrLf & vbCrLf)
sw.Close()

sw.Dispose()
Process.Start("C:\tEMP\Unhandled-Detailed.txt")
Posted
Comments
Richard Deeming 4-Nov-14 13:29pm    
Do you have an event handler for the DataSourceChanged event of a ComboBox control?

You need to understand the call stack and how exception work. An exception propagate up the stack by jumping from one "try" point to another. This is a kind of "time machine" mechanism.
I tried to explain it in my past answers (I am the author of a very early implementation of Structured Exception Handling, at the time when it was in CLU and then Ada, but no even in C++ yet):
Does Exception in C# Constructor Cause Caller Assignment to Fail?[^],
where was stored .net exceptions in operating system[^].

First of all, you need to understand what is the call stack and its role, and then you need to understand that the exception mechanism has its own stack which elements point to the positions in the call stack, per thread. It allows you to trace how the exception propagated to a certain point of your code.

In addition to understanding the theory, I can advise one practical step which can give you a clear vision of the stack in each particular case. Catch all exceptions somewhere on the top stack frame. Put a break point on the exception handler and run it under the debugger the way to observe the exception. When execution stops at the break point, open the Debug window called "Call stack". In this window, you can click on the lines each corresponding to some point on the call stack. On click, a source code window will be shown, with the cursor set on the point in code.

It will help you to understand the exception stack diagnostics. See also:
http://msdn.microsoft.com/en-us/library/system.diagnostics.stacktrace%28v=vs.110%29.aspx[^],
http://msdn.microsoft.com/en-us/library/system.diagnostics.stackframe%28v=vs.110%29.aspx[^].

—SA
 
Share this answer
 
Thanks for your reply.

Nothing for the data source changed event, but I found the solution in this on-line article...

http://connect.microsoft.com/VisualStudio/feedbackdetail/view/262053/autocompletesource-listitems-in-combobox-causes-exception-when-form-is-closed[^]

So i went into form closing and for the last line I added...

VB
If e.Cancel = False then cmbRecAcct.AutoCompleteMode = AutoCompleteMode.None


And that fixed it.
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 4-Nov-14 14:50pm    
How come you considered this as answer, and even self-accepted it formally?
This is not a "solution", but the abuse of this site.
—SA
Davester28 4-Nov-14 14:53pm    
I'm just documenting the solution for others to find. I dont understand what the abuse abuse is. I am new to this site, so please tell me what to correct. Thank you
Davester28 4-Nov-14 15:13pm    
Who else could mark if something solved my problem or not ? If someone else searches for the same exception message, and finds this thread, how are they to know what resolves it if I purposely left them in the dark ?
Sergey Alexandrovich Kryukov 4-Nov-14 15:39pm    
Sorry, I though this is the clarification to the question, not a solution.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900