views:

342

answers:

1

I've got a binding list, that under certain hard to reproduce conditions is throwing the following exception when a value is added to it:

System.ArgumentException: Complex DataBinding accepts as a data source either an IList or an IListSource. at System.ComponentModel.ReflectPropertyDescriptor.SetValue(Object component, Object value)
at System.Windows.Forms.Binding.SetPropValue(Object value)
at System.Windows.Forms.Binding.PushData(Boolean force)
at System.Windows.Forms.BindingManagerBase.PushData(Boolean& success)
at System.Windows.Forms.BindingManagerBase.PushData()
at System.Windows.Forms.CurrencyManager.CurrencyManager_PushData()
at System.Windows.Forms.CurrencyManager.OnItemChanged(ItemChangedEventArgs e)
at System.Windows.Forms.CurrencyManager.List_ListChanged(Object sender, ListChangedEventArgs e)
at System.ComponentModel.ListChangedEventHandler.Invoke(Object sender, ListChangedEventArgs e)
at System.ComponentModel.BindingList1.OnListChanged(ListChangedEventArgs e)
at System.ComponentModel.BindingList
1.InsertItem(Int32 index, T item)
at System.Collections.ObjectModel.Collection`1.Add(T item)
...

I could understand if it was happening when creating the list, or changing one of the properties, but this is only happening when adding certain values to it. It's declared like follows:

private BindingList<IBusinessObject> _bindingList = new BindingList<IBusinessObject>();

And then used later like so (which is where the exception is being thrown):

_bindingList.Add(myBusinessObject);

To make matters worse this is occuring in previously working production code where none of the code involved here has been edited recently. I have a suspicion this is some sort of subtle data interaction issue which is also why it's happening infrequently, but frankly I'm at a loss as the origin point for the exception is deep inside the .Net internals.

Update: It's not actually a single form, but rather a piece of the object model used to back several forms/dialogs. It's very complex code, and not code that I wrote but am merely maintaining/enhancing. After digging through the code, it looks like the BindingList gets added to some more domain objects and eventually used to populate a ImageListBox using a string property of the object. The string in question should never be null or blank, but because of where the code is located at and the difficultly in reproducing the error attaching a debugger to verify will be problematic. Could a null value cause the BindingList to throw an exception at such a distantly removed location from where the issue is actually located at? This object is literally inserted into 3 or 4 other objects/collections prior to eventually being assigned as the data source to the ImageListBox list in question (and even then it depends on a couple other selections as to exactly which one of the BindingList objects is eventually used to populate the list).

+1  A: 

It looks like you have the DataSource property of a list control of some kind bound to a property of your IBusinessObject, and that property is returning a value that is not valid as a DataSource. Can you be more specific about all of the bindings you are using on this form?