-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[Bug] NSInternalInconsistencyException exception on iOS with CollectionView #6920
Comments
I haven't looked at your code, but I remember getting a similar exception when the items collection was being updated on a thread other than the main UI thread. If you are not doing this, the renderer might be doing it. |
Hi @adrianknight89 I have the same issue (I commented on #5793) for my example repo I invoke on the main thread and still have the issue, if you any other ideas it would be most appreciated, thanks. |
@afk013 You're calling |
Hi @adrianknight89 sorry yes the |
I'm observing this issue in Forms As long as I clear the collection by some other means than For example: while (Things.Count > 0)
Things.RemoveAt(0); |
Fixed in 4.2.0.618605-pre2. |
I have NuGet version 4.2.0.618605-pre2 and still same problem. |
Sorry, but i've test but it still reproduction. (version 4.2.0.709249) |
im having this problem for |
Same issue here. Version 4.3.0.991221. |
@gabrielfreire and @JohnLivermore are you using grouping by any chance? |
No. We are using it in it's most basic form as a vertically displayed list binding to a List. We get the exception when switching the root navigation to a different stack. |
@JohnLivermore could you please open a separate issue for your case? That sounds like a different case than what this issue addressed. |
Even I'm having this issue with Xamarin Forms 4.4 |
This issue is still present. I tried to add items in UI thread too. But still not working. This is occurring in all iOS versions below iOS 13.
|
I have the same issue on XF 5.0.0.2012 |
1 similar comment
I have the same issue on XF 5.0.0.2012 |
This issue should be re-opened. I'm still having the issue on XF 5.0.0.2012. |
Yes this is happen to me as well after updating to 5.0.0.2012. The same code was working fine on 4.8.0.1687. If it helps, i'm using a using a grid layout when this crash happens. |
Same issue, switched from ListView to CollectionView 😔 |
Why this issue is closed? Is this issue resolved or any workaround? |
I would like to add that this also started happening to me after upgrading to 5.0.0.2012. It was working fine on 4.8.0.1451. I am using grouping in the cases where this error occurs. Without grouping, all seems to work fine. But grouping is a requirement. I tried using RemoveAt/Insert instead of Clear/Add, but no difference. Also tried BeginInvokeOnMainThread suggestion and still get the error. It does feel like something broke in XF 5.0 |
@Nadraw I'm having the same problem with Xamarin.Forms 5.0.0.2012. CollectionView throws this exception on iOS when using grouping. |
The problem has not been fixed yet |
See also #14362. A workaround for me was to initialize the ObservableCollection with one element. Any subsequent Add worked fine. The add of the first item of a grouped colllection is handled differently. |
It |
I'm getting this problem too. But only on iOS |
We're in 2022, and I'm still getting this issue in prod. version 5.0.0.2337 |
Hi all, Thank you in advance. |
Description
I have a Xamarin.Forms project that has a CollectionView that is bound to an ObservableCollection. If I call Clear() on the ObservableCollection and then call Add() to add an item I get the exception.
Steps to Reproduce
Expected Behavior
Item should be added.
Actual Behavior
Exception gets thrown. I was able to work around this by calling RemoveAt(0) in a while loop until the list is empty instead of using Clear() so no rush for me just wanted you guys to know about the bug.
Basic Information
Exception
Foundation.MonoTouchException: Objective-C exception thrown. Name: NSInternalInconsistencyException Reason: Invalid update: invalid number of items in section 0. The number of items contained in an existing section after the update (1) must be equal to the number of items contained in that section before the update (1), plus or minus the number of items inserted or deleted from that section (1 inserted, 0 deleted) and plus or minus the number of items moved into or out of that section (0 moved in, 0 moved out).
Native stack trace:
0 CoreFoundation 0x000000010ffb66fb __exceptionPreprocess + 331
1 libobjc.A.dylib 0x0000000110c3bac5 objc_exception_throw + 48
2 CoreFoundation 0x000000010ffb6482 +[NSException raise:format:arguments:] + 98
3 Foundation 0x000000010bf13927 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 194
4 UIKitCore 0x0000000119775479 -[UICollectionView _endItemAnimationsWithInvalidationContext:tentativelyForReordering:animator:] + 16127
5 UIKitCore 0x0000000119771239 -[UICollectionView _updateRowsAtIndexPaths:updateAction:updates:] + 519
6 UIKitCore 0x00000001197712c4 -[UICollectionView insertItemsAtIndexPaths:] + 64
7 CollectionsBugSample.iOS 0x0000000102d20999 xamarin_dyn_objc_msgSend + 217
8 ??? 0x00000001353135d7 0x0 + 5187384791
9 ??? 0x00000001352fd0d4 0x0 + 5187293396
10 ??? 0x00000001359a7baf 0x0 + 5194283951
11 ??? 0x0000000133dee5be 0x0 + 5165213118
12 CollectionsBugSample.iOS 0x0000000102b028a1 mono_jit_runtime_invoke + 1585
13 CollectionsBugSample.iOS 0x0000000102c139f4 mono_runtime_try_invoke + 148
14 CollectionsBugSample.iOS 0x0000000102c156af mono_runtime_invoke + 95
15 CollectionsBugSample.iOS 0x00000001029e7058 _ZL31native_to_managed_trampoline_20P11objc_objectP13objc_selectorPP11_MonoMethodj + 248
16 CollectionsBugSample.iOS 0x00000001029eb654 -[__MonoMac_NSAsyncActionDispatcher xamarinApplySelector] + 52
17 Foundation 0x000000010bfa5878 __NSThreadPerformPerform + 331
18 CoreFoundation 0x000000010ff1dbe1 CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 17
19 CoreFoundation 0x000000010ff1d463 __CFRunLoopDoSources0 + 243
20 CoreFoundation 0x000000010ff17b1f __CFRunLoopRun + 1231
21 CoreFoundation 0x000000010ff17302 CFRunLoopRunSpecific + 626
22 GraphicsServices 0x0000000112b092fe GSEventRunModal + 65
23 UIKitCore 0x0000000119ee2ba2 UIApplicationMain + 140
24 ??? 0x0000000135029052 0x0 + 5184327762
25 ??? 0x0000000135028de3 0x0 + 5184327139
26 ??? 0x00000001341191a3 0x0 + 5168533923
27 CollectionsBugSample.iOS 0x0000000102b028a1 mono_jit_runtime_invoke + 1585
28 CollectionsBugSample.iOS 0x0000000102c12058 mono_runtime_invoke_checked + 136
29 CollectionsBugSample.iOS 0x0000000102c176dd mono_runtime_exec_main_checked + 109
30 CollectionsBugSample.iOS 0x0000000102a6dbf7 mono_jit_exec + 311
31 CollectionsBugSample.iOS 0x0000000102d1e864 xamarin_main + 2708
32 CollectionsBugSample.iOS 0x0000000102a496f2 main + 82
33 libdyld.dylib 0x0000000112152541 start + 1
at ObjCRuntime.Runtime.ThrowNSException (System.IntPtr ns_exception) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.10.0.157/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 (wrapper native-to-managed) ObjCRuntime.Runtime.throw_ns_exception(intptr)
at (wrapper managed-to-native) ObjCRuntime.Messaging.void_objc_msgSend_IntPtr(intptr,intptr,intptr)
at UIKit.UICollectionView.InsertItems (Foundation.NSIndexPath[] indexPaths) [0x00022] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.10.0.157/src/Xamarin.iOS/UIKit/UICollectionView.g.cs:471
at Xamarin.Forms.Platform.iOS.ObservableItemsSource.Add (System.Collections.Specialized.NotifyCollectionChangedEventArgs args) [0x00035] in D:\a\1\s\Xamarin.Forms.Platform.iOS\CollectionView\ObservableItemsSource.cs:124
at Xamarin.Forms.Platform.iOS.ObservableItemsSource.CollectionChanged (System.Object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs args) [0x00023] in D:\a\1\s\Xamarin.Forms.Platform.iOS\CollectionView\ObservableItemsSource.cs:50
at System.Collections.ObjectModel.ObservableCollection
1[T].OnCollectionChanged (System.Collections.Specialized.NotifyCollectionChangedEventArgs e) [0x00018] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.10.0.157/src/Xamarin.iOS/external/corefx/src/System.ObjectModel/src/System/Collections/ObjectModel/ObservableCollection.cs:263 at System.Collections.ObjectModel.ObservableCollection
1[T].OnCollectionChanged (System.Collections.Specialized.NotifyCollectionChangedAction action, System.Object item, System.Int32 index) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.10.0.157/src/Xamarin.iOS/external/corefx/src/System.ObjectModel/src/System/Collections/ObjectModel/ObservableCollection.cs:338at System.Collections.ObjectModel.ObservableCollection
1[T].InsertItem (System.Int32 index, T item) [0x0001a] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.10.0.157/src/Xamarin.iOS/external/corefx/src/System.ObjectModel/src/System/Collections/ObjectModel/ObservableCollection.cs:196 at System.Collections.ObjectModel.Collection
1[T].Add (T item) [0x00020] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.10.0.157/src/Xamarin.iOS/external/corefx/src/Common/src/CoreLib/System/Collections/ObjectModel/Collection.cs:73at CollectionsBugSample.MainPage.<AddButton_Clicked>b__3_1 () [0x00013] in C:\Users\Jim\Desktop\CollectionsBugSample\CollectionsBugSample\CollectionsBugSample\MainPage.xaml.cs:50
--- End of stack trace from previous location where exception was thrown ---
at (wrapper managed-to-native) ObjCRuntime.Messaging.void_objc_msgSend_IntPtr(intptr,intptr,intptr)
at UIKit.UICollectionView.InsertItems (Foundation.NSIndexPath[] indexPaths) [0x00022] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.10.0.157/src/Xamarin.iOS/UIKit/UICollectionView.g.cs:471
at Xamarin.Forms.Platform.iOS.ObservableItemsSource.Add (System.Collections.Specialized.NotifyCollectionChangedEventArgs args) [0x00035] in D:\a\1\s\Xamarin.Forms.Platform.iOS\CollectionView\ObservableItemsSource.cs:124
at Xamarin.Forms.Platform.iOS.ObservableItemsSource.CollectionChanged (System.Object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs args) [0x00023] in D:\a\1\s\Xamarin.Forms.Platform.iOS\CollectionView\ObservableItemsSource.cs:50
at System.Collections.ObjectModel.ObservableCollection
1[T].OnCollectionChanged (System.Collections.Specialized.NotifyCollectionChangedEventArgs e) [0x00018] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.10.0.157/src/Xamarin.iOS/external/corefx/src/System.ObjectModel/src/System/Collections/ObjectModel/ObservableCollection.cs:263 at System.Collections.ObjectModel.ObservableCollection
1[T].OnCollectionChanged (System.Collections.Specialized.NotifyCollectionChangedAction action, System.Object item, System.Int32 index) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.10.0.157/src/Xamarin.iOS/external/corefx/src/System.ObjectModel/src/System/Collections/ObjectModel/ObservableCollection.cs:338at System.Collections.ObjectModel.ObservableCollection
1[T].InsertItem (System.Int32 index, T item) [0x0001a] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.10.0.157/src/Xamarin.iOS/external/corefx/src/System.ObjectModel/src/System/Collections/ObjectModel/ObservableCollection.cs:196 at System.Collections.ObjectModel.Collection
1[T].Add (T item) [0x00020] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.10.0.157/src/Xamarin.iOS/external/corefx/src/Common/src/CoreLib/System/Collections/ObjectModel/Collection.cs:73at CollectionsBugSample.MainPage.<AddButton_Clicked>b__3_1 () [0x00013] in C:\Users\Jim\Desktop\CollectionsBugSample\CollectionsBugSample\CollectionsBugSample\MainPage.xaml.cs:50 0 CoreFoundation 0x000000010ffb66fb __exceptionPreprocess + 331
1 libobjc.A.dylib 0x0000000110c3bac5 objc_exception_throw + 48
2 CoreFoundation 0x000000010ffb6482 +[NSException raise:format:arguments:] + 98
3 Foundation 0x000000010bf13927 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 194
4 UIKitCore 0x0000000119775479 -[UICollectionView _endItemAnimationsWithInvalidationContext:tentativelyForReordering:animator:] + 16127
5 UIKitCore 0x0000000119771239 -[UICollectionView _updateRowsAtIndexPaths:updateAction:updates:] + 519
6 UIKitCore 0x00000001197712c4 -[UICollectionView insertItemsAtIndexPaths:] + 64
7 CollectionsBugSample.iOS 0x0000000102d20999 xamarin_dyn_objc_msgSend + 217
8 ??? 0x00000001353135d7 0x0 + 5187384791
9 ??? 0x00000001352fd0d4 0x0 + 5187293396
10 ??? 0x00000001359a7baf 0x0 + 5194283951
11 ??? 0x0000000133dee5be 0x0 + 5165213118
12 CollectionsBugSample.iOS 0x0000000102b028a1 mono_jit_runtime_invoke + 1585
13 CollectionsBugSample.iOS 0x0000000102c139f4 mono_runtime_try_invoke + 148
14 CollectionsBugSample.iOS 0x0000000102c156af mono_runtime_invoke + 95
15 CollectionsBugSample.iOS 0x00000001029e7058 _ZL31native_to_managed_trampoline_20P11objc_objectP13objc_selectorPP11_MonoMethodj + 248
16 CollectionsBugSample.iOS 0x00000001029eb654 -[__MonoMac_NSAsyncActionDispatcher xamarinApplySelector] + 52
17 Foundation 0x000000010bfa5878 __NSThreadPerformPerform + 331
18 CoreFoundation 0x000000010ff1dbe1 CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 17
19 CoreFoundation 0x000000010ff1d463 __CFRunLoopDoSources0 + 243
20 CoreFoundation 0x000000010ff17b1f __CFRunLoopRun + 1231
21 CoreFoundation 0x000000010ff17302 CFRunLoopRunSpecific + 626
22 GraphicsServices 0x0000000112b092fe GSEventRunModal + 65
23 UIKitCore 0x0000000119ee2ba2 UIApplicationMain + 140
24 ??? 0x0000000135029052 0x0 + 5184327762
25 ??? 0x0000000135028de3 0x0 + 5184327139
26 ??? 0x00000001341191a3 0x0 + 5168533923
27 CollectionsBugSample.iOS 0x0000000102b028a1 mono_jit_runtime_invoke + 1585
28 CollectionsBugSample.iOS 0x0000000102c12058 mono_runtime_invoke_checked + 136
29 CollectionsBugSample.iOS 0x0000000102c176dd mono_runtime_exec_main_checked + 109
30 CollectionsBugSample.iOS 0x0000000102a6dbf7 mono_jit_exec + 311
31 CollectionsBugSample.iOS 0x0000000102d1e864 xamarin_main + 2708
32 CollectionsBugSample.iOS 0x0000000102a496f2 main + 82
33 libdyld.dylib 0x0000000112152541 start + 1
CollectionsBugSample.zip
The text was updated successfully, but these errors were encountered: