Closed fnoomen closed 4 years ago
hi, when using addrange() in 4.7.1142 i get error bat when using add() no error
Foundation.MonoTouchException: Objective-C exception thrown. Name: NSRangeException Reason: *** -[NSArrayM objectAtIndex:]: index 18446744073709551615 beyond bounds [0 .. 20] Native stack trace: 0 CoreFoundation 0x00007fff23e3cf0e exceptionPreprocess + 350 1 libobjc.A.dylib 0x00007fff50ba89b2 objc_exception_throw + 48 2 CoreFoundation 0x00007fff23ecfa51 _CFThrowFormattedException + 194 3 CoreFoundation 0x00007fff23d50679 -[__NSArrayM objectAtIndex:] + 169 4 UIKitCore 0x00007fff484991df -[_UIFlowLayoutSection frameForItemAtIndexPath:] + 363 5 UIKitCore 0x00007fff48485566 -[UICollectionViewFlowLayout _frameForItem:inSection:usingData:] + 153 6 UIKitCore 0x00007fff4847ea7e -[UICollectionViewFlowLayout layoutAttributesForItemAtIndexPath:usingData:] + 376 7 UIKitCore 0x00007fff4847ee16 -[UICollectionViewFlowLayout layoutAttributesForItemAtIndexPath:] + 504 8 UIKitCore 0x00007fff4848a799 -[UICollectionViewLayout prepareForCollectionViewUpdates:] + 3352 9 GroceryStore.iOS 0x0000000102c64c3c xamarin_dyn_objc_msgSendSuper + 220 10 ??? 0x000000010a05bcd0 0x0 + 4463115472
at ObjCRuntime.Runtime.ThrowNSException (System.IntPtr ns_exception) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/13.18.2.1/src/Xamarin.iOS/ObjCRuntime/Runtime.cs:406
at ObjCRuntime.Runtime.throw_ns_exception (System.IntPtr exc) [0x00000] in /Users/builder/jenkins/workspace/xamarin-macios/xamarin-macios/runtime/Delegates.generated.cs:128
at at (wrapper native-to-managed) ObjCRuntime.Runtime.throw_ns_exception(intptr)
at at (wrapper managed-to-native) ObjCRuntime.Messaging.void_objc_msgSendSuper_IntPtr(intptr,intptr,intptr)
at UIKit.UICollectionViewLayout.PrepareForCollectionViewUpdates (UIKit.UICollectionViewUpdateItem[] updateItems) [0x0003f] in /Library/Frameworks/Xamarin.iOS.framework/Versions/13.18.2.1/src/Xamarin.iOS/UICollectionViewLayout.g.cs:528
at Xamarin.Forms.Platform.iOS.ItemsViewLayout.PrepareForCollectionViewUpdates (UIKit.UICollectionViewUpdateItem[] updateItems) [0x00000] in D:\a\1\s\Xamarin.Forms.Platform.iOS\CollectionView\ItemsViewLayout.cs:403
at at (wrapper managed-to-native) ObjCRuntime.Messaging.void_objc_msgSend_IntPtr_IntPtr(intptr,intptr,intptr,intptr)
at UIKit.UICollectionView.PerformBatchUpdates (System.Action updates, UIKit.UICompletionHandler completed) [0x00055] in /Library/Frameworks/Xamarin.iOS.framework/Versions/13.18.2.1/src/Xamarin.iOS/UICollectionView.g.cs:569
at Xamarin.Forms.Platform.iOS.ObservableItemsSource.BatchUpdate (System.Action update) [0x00014] in D:\a\1\s\Xamarin.Forms.Platform.iOS\CollectionView\ObservableItemsSource.cs:312
at Xamarin.Forms.Platform.iOS.ObservableItemsSource.Add (System.Collections.Specialized.NotifyCollectionChangedEventArgs args) [0x000ec] in D:\a\1\s\Xamarin.Forms.Platform.iOS\CollectionView\ObservableItemsSource.cs:174
at at (wrapper managed-to-native) ObjCRuntime.Messaging.void_objc_msgSendSuper_IntPtr(intptr,intptr,intptr)
at UIKit.UICollectionViewLayout.PrepareForCollectionViewUpdates (UIKit.UICollectionViewUpdateItem[] updateItems) [0x0003f] in /Library/Frameworks/Xamarin.iOS.framework/Versions/13.18.2.1/src/Xamarin.iOS/UICollectionViewLayout.g.cs:528
at Xamarin.Forms.Platform.iOS.ItemsViewLayout.PrepareForCollectionViewUpdates (UIKit.UICollectionViewUpdateItem[] updateItems) [0x00000] in D:\a\1\s\Xamarin.Forms.Platform.iOS\CollectionView\ItemsViewLayout.cs:403
at at (wrapper managed-to-native) ObjCRuntime.Messaging.void_objc_msgSend_IntPtr_IntPtr(intptr,intptr,intptr,intptr)
at UIKit.UICollectionView.PerformBatchUpdates (System.Action updates, UIKit.UICompletionHandler completed) [0x00055] in /Library/Frameworks/Xamarin.iOS.framework/Versions/13.18.2.1/src/Xamarin.iOS/UICollectionView.g.cs:569
at Xamarin.Forms.Platform.iOS.ObservableItemsSource.BatchUpdate (System.Action update) [0x00014] in D:\a\1\s\Xamarin.Forms.Platform.iOS\CollectionView\ObservableItemsSource.cs:312
at Xamarin.Forms.Platform.iOS.ObservableItemsSource.Add (System.Collections.Specialized.NotifyCollectionChangedEventArgs args) [0x000ec] in D:\a\1\s\Xamarin.Forms.Platform.iOS\CollectionView\ObservableItemsSource.cs:174
at Xamarin.Forms.Platform.iOS.ObservableItemsSource.CollectionChanged (System.Collections.Specialized.NotifyCollectionChangedEventArgs args) [0x00061] in D:\a\1\s\Xamarin.Forms.Platform.iOS\CollectionView\ObservableItemsSource.cs:117
at Xamarin.Forms.Platform.iOS.ObservableItemsSource.CollectionChanged (System.Object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs args) [0x000b7] in D:\a\1\s\Xamarin.Forms.Platform.iOS\CollectionView\ObservableItemsSource.cs:108
at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.
@fnoomen Could you attach the reproduction sample?
the problem in my custom class, Archive.zip its when using AddRange
using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Collections.Specialized; using System.ComponentModel;
namespace CollectionView_test.ViewModels
{
[Xamarin.Forms.Internals.Preserve(AllMembers = true)]
public class MyObservableCollection
public virtual void AddRange(IEnumerable<T> items)
{
_disableOnCollectionChanged = true;
foreach (var item in items)
Items.Add(item);
_disableOnCollectionChanged = false;
NotifyCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, items));
}
protected override void OnCollectionChanged(NotifyCollectionChangedEventArgs e)
{
if (!_disableOnCollectionChanged)
{
try
{
base.OnCollectionChanged(e);
}
catch (NullReferenceException ex)
{
System.Diagnostics.Debug.WriteLine(ex);
//TODO HACK some strange Xamarin.Forms exceptionw when using grouping + fast scroll shortname list !?
}
}
}
internal void NotifyCollectionChanged(NotifyCollectionChangedEventArgs args)
{
this.OnCollectionChanged(args);
this.OnPropertyChanged(new PropertyChangedEventArgs("Count"));
this.OnPropertyChanged(new PropertyChangedEventArgs("Item[]"));
}
}
}
This appears to just be more information about #10826.
So, closing as duplicate, I guess?
@YZahringer Thanks for the reproduction sample. I have done several tests and can reproduce the issue using 4.6 and 4.7-pre2.
Then, I have created a tests in Xamarin.Forms Core Gallery using the MvvmHelpers
ObservableRangeCollection
code and, cannot reproduce the issue: https://gist.github.com/jsuarezruiz/bbed609b8382a72c6304c4244f48b964I will check if it has been fixed by another issue fix, etc.
Originally posted by @jsuarezruiz in https://github.com/xamarin/Xamarin.Forms/issues/10826#issuecomment-637494051