Cysharp/ObservableCollections

A zipped sequence causes an exception in ObservableList.AddRange.

yossiepon opened this issue · 2 comments

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());

This issue is stale because it has been open 90 days with no activity. Remove stale label or comment or this will be closed in 7 days.