ObservableCollections
ObservableCollections copied to clipboard
A zipped sequence causes an exception in ObservableList.AddRange.
I am getting an exception with the code below.
using ObservableCollections;
var seq1 = Enumerable.Range(0, 1);
var seq2 = Enumerable.Range(0, 1);
var zippedSeq = seq1.Zip(seq2, (num1, num2) => (num1, num2));
var list = new ObservableList<(int,int)>();
list.AddRange(zippedSeq); // IndexOutOfRangeException raised.
I think there's something wrong with the CloneCollection construction process when the enumerator doesn't support NonEnumeratedCount.
CloneCollection.TryEnsureCapacity seems to be returning an empty array.
Hi, I remember falling int the same issue and if i recall correctly the reason for the exception was mapping the input sequence onto a Span. The fix is to materialize the sequence first, for example with .ToList() before calling AddRange():
list.AddRange(zippedSeq.ToList());