Why is BindingList throwing System.ArgumentException when adding member
I have a binding list that, under certain conditions, is difficult to reproduce, throws the following exception when a value is added to it:
System.ArgumentException: Complex DataBinding accepts either IList or IListSource as data source. at System.ComponentModel.ReflectPropertyDescriptor.SetValue (object component, object value)
at System.Windows.Forms.Binding.SetPropValue (object value)
at System.Windows.Forms.Binding.PushData (boolean)
at System.Windows.Forms. BindingManagerBase.PushData (Boolean & success)
in System.Windows.Forms.BindingManagerBase.PushData ()
in System.Windows.Forms.CurrencyManager.CurrencyManager_PushData ()
in System.Windows.Forms.CurrencyManager.OnItemChanged (ItemChangedEventArgs e)
in System.Windows .Forms.CurrencyManager.List_ListChanged (Object Sender, ListChangedEventArgs e)
at System.ComponentModel.ListChangedEventHandler.Invoke (object sender, ListChangedEventArgs e)
at System.ComponentModel.BindingList 1.InsertItem (Int32 index, T item) at System.Collections.ObjectModel.Collection`1.Add (T item) ...1.OnListChanged(ListChangedEventArgs e)
at System.ComponentModel.BindingList
I could figure out if this was happening when creating the list or changing one of the properties, but it only happens when certain values are added to it. He stated the following:
private BindingList<IBusinessObject> _bindingList = new BindingList<IBusinessObject>();
And then used later as if (in which the exception occurs):
_bindingList.Add(myBusinessObject);
To make matters worse, this happens in previously working production code, where none of the code shown here has been recently edited. I have a suspicion that this is some kind of subtle data interoperability issue and also why this happens infrequently, but frankly, I am at a loss as the original point of the exception is inside .Net.
Update: Actually it is not a single form, but a fragment of an object model used to support multiple forms / dialogs. This is very complex code, not the code I wrote, but just maintain / improve. After digging around in the code, it looks like the BindingList is being added to some additional domain objects and eventually used to populate the ImageListBox using the string property of the object. The line in question should never be empty or empty, but because of where the code is and it is difficult to reproduce the error attaching a debugger to check it will be problematic. Could a null value cause the BindingList to throw an exception at such a remote location where the problem is actually from? This object is literally inserted into 3 or 4 other objects / collections beforehow it will be assigned as a data source to the ImageListBox (and even then it depends on a couple of other choices as to which of the BindingList objects is ultimately used to populate the list).
a source to share