Hi there,
I've a problem that costs me hours without finding any solution. I've a CAB-Application, containing a UserControl with several controls on it. I've a UltraComboEditor to show countries whereas the country names are fetched from the database into business objects and I'm using databinding to show those names in the Combo. Furthermore I'm using databinding to store the id (value) for the selected country into another business object. That all works perfectly fine so when I select a country with the combo the appropriate id for that country is stored in the business object.
My problem is when selecting a country but closing the entire application afterwards I get following exception:
System.ArgumentException: Cannot bind to the property or column CountryId on the DataSource.
When I set the focus onto another control after selection country in the combo and before closing the application there is no exception.
Any hints would be appriciated. Find the entire exception below:
System.ArgumentException: Cannot bind to the property or column CountryId on the DataSource.Parameter name: dataMember at System.Windows.Forms.BindToObject.CheckBinding() at System.Windows.Forms.BindToObject.SetBindingManagerBase(BindingManagerBase lManager) 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 Infragistics.Win.UltraWinEditors.UltraComboEditor.OnBindingContextChanged(EventArgs e) at System.Windows.Forms.Control.CreateControl() at System.Windows.Forms.Control.WmShowWindow(Message& m) at System.Windows.Forms.Control.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.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) at System.Windows.Forms.UnsafeNativeMethods.IntCreateWindowEx(Int32 dwExStyle, String lpszClassName, String lpszWindowName, Int32 style, Int32 x, Int32 y, Int32 width, Int32 height, HandleRef hWndParent, HandleRef hMenu, HandleRef hInst, Object pvParam) at System.Windows.Forms.UnsafeNativeMethods.CreateWindowEx(Int32 dwExStyle, String lpszClassName, String lpszWindowName, Int32 style, Int32 x, Int32 y, Int32 width, Int32 height, HandleRef hWndParent, HandleRef hMenu, HandleRef hInst, Object pvParam) at System.Windows.Forms.NativeWindow.CreateHandle(CreateParams cp) at System.Windows.Forms.Control.CreateHandle() at System.Windows.Forms.Control.get_Handle() at System.Windows.Forms.Control.PointToClientInternal(Point p) at System.Windows.Forms.Control.PointToClient(Point p) at Infragistics.Win.UltraWinEditors.StyleUtils.IsHottracking(Control ctrl) at Infragistics.Win.UltraWinEditors.TextEditorControlBase.ResolveAppearance(AppearanceData& appearance, AppearancePropFlags& requestedProps, Boolean includeNullTextAppearance) at Infragistics.Win.UltraWinEditors.TextEditorControlBase.ResolveAppearance(AppearanceData& appearance, AppearancePropFlags& requestedProps) at Infragistics.Win.UltraWinEditors.EditorWithComboOwner.ResolveAppearance(Object ownerContext, AppearanceData& appearance, AppearancePropFlags& requestedProps, EmbeddableEditorArea area, Boolean hotTracking, String customArea) at Infragistics.Win.EditorWithTextAndDropDownUIElementBase.InitAppearance(AppearanceData& appearance, AppearancePropFlags& requestedPropFlags) at Infragistics.Win.EmbeddableUIElementBase.InitAppearanceInternal(AppearanceData& appearance, AppearancePropFlags& requestedProps) at Infragistics.Win.EmbeddableTextBox.ApplyAppearance() at Infragistics.Win.EditorWithCombo.Infragistics.Win.IValueListOwner.OnSelectedItemChanged() at Infragistics.Win.ValueList.ProcessSelectedIndexChanged(Int32 selectedIndex, Boolean commit) at Infragistics.Win.ValueList.set_SelectedIndex(Int32 value) at Infragistics.Win.BindableValueList.SetDataSource(Object value, Boolean notify) at Infragistics.Win.BindableValueList.SetDataBinding(Object dataSource, String dataMember) at Infragistics.Win.BindableValueList.OnDataSourceDisposed(Object sender, EventArgs e) at System.EventHandler.Invoke(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 Altova.OrderManagement.Common.OrderUserControl.Dispose(Boolean disposing) in C:\projects\ACS\Products\OrderManagement\Common\OrderUserControl.Designer.cs:line 18 at Altova.OrderManagement.DraftOrders.DraftOrders.Dispose(Boolean disposing) in C:\projects\ACS\Products\OrderManagement\DraftOrders\DraftOrders.Designer.cs:line 20 at System.ComponentModel.Component.Dispose() at System.Windows.Forms.Control.Dispose(Boolean disposing) at Microsoft.Practices.CompositeUI.WinForms.DeckWorkspace.Dispose(Boolean disposing) at System.ComponentModel.Component.Dispose() at System.Windows.Forms.Control.Dispose(Boolean disposing) at System.ComponentModel.Component.Dispose() at System.Windows.Forms.Control.Dispose(Boolean disposing) at System.Windows.Forms.ContainerControl.Dispose(Boolean disposing) at System.ComponentModel.Component.Dispose() at System.Windows.Forms.Control.Dispose(Boolean disposing) at System.Windows.Forms.ContainerControl.Dispose(Boolean disposing) at System.Windows.Forms.Form.Dispose(Boolean disposing) at Altova.Acs.ShellForm.Dispose(Boolean disposing) in C:\projects\ACS\Products\ACS\ShellForm.designer.cs:line 20 at System.ComponentModel.Component.Dispose() at System.Windows.Forms.Form.WmClose(Message& m) at System.Windows.Forms.Form.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.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) at System.Windows.Forms.UnsafeNativeMethods.CallWindowProc(IntPtr wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam) at System.Windows.Forms.NativeWindow.DefWndProc(Message& m) at System.Windows.Forms.Form.DefWndProc(Message& m) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.ScrollableControl.WndProc(Message& m) at System.Windows.Forms.ContainerControl.WndProc(Message& m) at System.Windows.Forms.Form.WmSysCommand(Message& m) at System.Windows.Forms.Form.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.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) at System.Windows.Forms.UnsafeNativeMethods.CallWindowProc(IntPtr wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam) at System.Windows.Forms.NativeWindow.DefWndProc(Message& m) at System.Windows.Forms.Form.DefWndProc(Message& m) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.ScrollableControl.WndProc(Message& m) at System.Windows.Forms.ContainerControl.WndProc(Message& m) at System.Windows.Forms.Form.WmNcButtonDown(Message& m) at System.Windows.Forms.Form.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.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg) at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData) at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context) at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context) at System.Windows.Forms.Application.Run(Form mainForm) at Infragistics.Practices.CompositeUI.WinForms.IGFormShellApplication`2.Start() in C:\projects\ACS\Externals\Infragistics\NetAdvantage 2010.1\Windows Forms\CAB Extensibility Kit\Source\Infragistics.CompositeUI.WinForms\Application\IGFormShellApplication.cs:line 24 at Microsoft.Practices.CompositeUI.CabApplication`1.Run() at Altova.Acs.ShellApplication.Main() in C:\projects\ACS\Products\ACS\ShellApplication.cs:line 39
What version of the controls are you using? Do you have the latest service release?
It's hard to tell from just a call stack, but it looks like your BindingSource is getting disposed and this is triggering the UltraComboEditor to try to repaint itself which is causing it to try to access the data source, which was already disposed.
If that's the case, then you might be able to work around this for now by changing the order of things and making sure that the UltraComboEditor is disposed (in the OnDispose of the form) before the BindingSource.
Hi Mike,
thanks for your reply. Currently I'm using version 10.1.20101.2013 but I'll soon change to version 10.2. I did a lot of further investigations on that problem yesterday, found out that it happens in the Dispose method of the UserControl which is generated by VisualStudio Designer and looks like depicted below:
/// <summary> /// Clean up any resources being used./// </summary>/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>protected override void Dispose(bool disposing){ if (disposing && (components != null)) { // During executing the function the exception is raised! components.Dispose(); } base.Dispose(disposing);}
As marked in the code snippet the exception is raised when components.Dispose() is executed. I don't know the magic behind this function but my guess was that it iterates through all components and calls Dispose function on each but when I replaced the function call with this iteration the exception has not been raised so there seems to be more functionality behind. Personally I've also the impression that the UltraComboEditor is trying to access the BindingSource which has been disposed already.
What I've found out as well is that updating of the CountryId in the Business Object is done when closing the entire application so at that moment both the BindingSource and the Business Object have not been disposed, the data binding is intact at that moment. I've also done a test by introducing another Property called 'Dummy' bound the UltraComboEditor onto that property on the same Business Object but the result was the same.
I've found a workaround which works although I'm not to happy with it. Since the controls are on a UserControl I don't get a FormClosing event so I'm subscribing for the FormClosing event of the parent control. When this event is fired I just set the focus onto next control in tab order which does updating of underlaying business object before all disposing of objects is started. As I mentioned before I see it as a work around and if I find a more appropriate solution I'll replace it.
Regards, Wolfgang