Using ObservableRangeCollection to Add Ranges throws exception

I tried to change my implementation to make use of the Xamarin Toolkit  ObservableRangeCollection instead of adding every element to the  ObservableCollection one by one.

But the notification throws an error when adding the range.


public ObservableRangeCollection<Class> Items { get; set; } = new ObservableRangeCollection<Class>();

Items.AddRange(items.Where(x => !Items.Contains(x)));

throws exception 

Index was out of range. Must be non-negative and less than the size of the collection.

Parameter name: index


  at System.Collections.Generic.List`1[T].get_Item (System.Int32 index) [0x00009] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corefx/src/Common/src/CoreLib/System/Collections/Generic/List.cs:161

  at System.Collections.Generic.List`1[T].System.Collections.IList.get_Item (System.Int32 index) [0x00000] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corefx/src/Common/src/CoreLib/System/Collections/Generic/List.cs:188

  at System.Collections.Specialized.ReadOnlyList.get_Item (System.Int32 index) [0x00000] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corefx/src/System.ObjectModel/src/System/Collections/Specialized/NotifyCollectionChangedEventArgs.cs:407

  at Syncfusion.SfSchedule.XForms.Droid.SfScheduleMapping.Appointments_CollectionChanged (System.Object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) [0x00028] in <82439d946afb4ad698e69aca95eac32c>:0

  at System.Collections.ObjectModel.ObservableCollection`1[T].OnCollectionChanged (System.Collections.Specialized.NotifyCollectionChangedEventArgs e) [0x00018] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corefx/src/System.ObjectModel/src/System/Collections/ObjectModel/ObservableCollection.cs:263

  at Xamarin.CommunityToolkit.ObjectModel.ObservableRangeCollection`1[T].RaiseChangeNotificationEvents (System.Collections.Specialized.NotifyCollectionChangedAction action, System.Collections.Generic.List`1[T] changedItems, System.Int32 startingIndex) [0x00039] in <0e226e856d614438a084204b98adfccf>:0

  at Xamarin.CommunityToolkit.ObjectModel.ObservableRangeCollection`1[T].AddRange (System.Collections.Generic.IEnumerable`1[T] collection, System.Collections.Specialized.NotifyCollectionChangedAction notificationMode) [0x00061] in <0e226e856d614438a084204b98adfccf>:0


1 Reply

SS SaiGanesh Sakthivel Syncfusion Team August 26, 2021 10:47 AM UTC

Hi Michael, 
 
Thank you for the contacting syncfusion support. 
 
#Regarding ObservableRangeCollection to Add Ranges throws exception 
Based on the given information, we have prepared the sample and check the reported scenario from our end. we regret to inform you that we could not replicate the reported scenario from our side. We have tested the sample with Android 9 (Honor device). Please refer to the tested sample and tested sample video in the following link for your reference. 
 
 
 
Please check the sample and let us know if you still facing the same issue? If not, please modify the sample based on your scenario and revert us back with the following details, 
 
·       Share the syncfusion version used in the sample. 
·       Share the Xamarin version version used in the sample. 
·       Share the issue replicate the platform. 
·       Share the issue replicate the video or reproduce. 
 
Regards, 
SaiGanesh Sakthivel 


Loader.
Up arrow icon