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
yesterday one of my colleagues gave me exactly the same link as you did for stepping into .NET code so I gave it a try but wasn't very successful. Immediately after stepping into components.Dispose() function call my program was in a finally-block somewhere in class Control.
I took your hint that the order of binding sources may cause the problems, tried to change them and after some tests finally the exception disappeared. What I've found out is that the two binding sources the UltraComboEditor is working with have to be in following order in the InitializeComponent function:
this.contactInfoBindingSource = new System.Windows.Forms.BindingSource(this.components);this.countryBindingSource = new System.Windows.Forms.BindingSource(this.components);
contactInfoBindingSource is the BindingSource where the CountryId is updated by the UltraComboEditor after selecting another country. The other BindingSource countryBindingSource holds the available countries.
I tried to set the order causing the exception also in the demo project but there it works independent of the order the BindingSource objects are created so there seems to be other dependencies as well but maybe it's a hint for your designers since other customers maybe experience same problems?
Btw I've upgraded to NetAdvantage 10.2 today as well and the problem is the same there. I've also tried to use UltraCombo instead of UltraComboEditor and this Control works also fine so it's only UltraComboEditor that makes the problems.
Thanks again for your support!
Hi Wolfgang,
qbupoew said:My next guess was that since I'm having 19 BindingSource components in the main application that this makes a difference
I'm sure it's not the number of BindingSources, but probably some interaction between them or the order in which they are performing operations.
qbupoew said:It would be very interesting what happens in components.Dispose() function in Dispose of the UserControl. I don't have the source code for it but maybe you at Infragistics do have any deeper knowledge which would be helpful for our further investigations. Any other hints what else I could try is appreciated.
You might want to check out this link: Configuring Visual Studio to Debug .NET Framework Source Code - Shawn Burke's Blog - Site Home - MSDN Blogs
This shows you how you can set up Visual Studio to step into the DotNet Framework code.
I've created a project that is similar structured to our main business application but unfortunately there this problem with the exception does not come up so I'm at the moment not able to send you such a project. Anyhow, I've made some further tests with new results:
The weird thing is that now I've a new UltraComboEditor with a totally simple Business Object behind and it is causing the exception. If I just change the DataSource property of that UltraComboEditor to write into CountryId of Order BO there is no exception! It really seems that the order of how the things are disposed causes the problem.
My next guess was that since I'm having 19 BindingSource components in the main application that this makes a difference so I've added that amount of binding sources to the test project but that didn'tmake any changes.
It would be very interesting what happens in components.Dispose() function in Dispose of the UserControl. I don't have the source code for it but maybe you at Infragistics do have any deeper knowledge which would be helpful for our further investigations. Any other hints what else I could try is appreciated.
Hi WolfGang,
My guess is that your workaround probably isn't totally reliable. The issue is probably occurring because of the order in which things are getting disposed. I can't see why the order would have changed with your loop or why the order of disposing the components would matter, since the combo is not a component, though. That's puzzling.
If you can duplicate this in a small sample project, we would certainly be happy to track it down and fix it and possibly provide you with a more reliable workaround in the mean time. But without being able to duplicate the issue, there's no much we can do.