2

Closed

Small "bug" in BindableCollection<T>

description

In "RemoveRange(IEnumerable<T> items)" in INPC.cs around line 540 the items get removed by:

foreach(var item in items) {
var index = IndexOf(item);
RemoveItemBase(index);
}

In case one of the items is not present, "index" is -1 and RemoveItemBase eventually results in an ArgumentOutOfRangeException. I'm not sure if this is the desired behavior but I think RemoveItemBase(index) should only be called here if the index is >= 0. This would be more in line with other ICollection implementations in .NET which simply return false if one tries to remove a non-existent item. If one tries to call RemoveAt(-1) it's a different matter and an exception is justified by the fact that the index comes from outside. But in RemoveRange we talk about internal code.
Closed Aug 15, 2012 at 4:52 AM by EisenbergEffect
Fixed in a58cb4f6ef2e

comments

tibel wrote Jul 26, 2012 at 8:47 PM

I think this bug is not so small, as it might seem.

The exception is raised on another thread (the GUI thread), when called from a worker thread.
There is no exception handling and no marshaling the exception back in the right thread.
So this might lead to an unpredictable behavior.