Since the last update of Xamarin Forms 4.5 the app breaks on a Grouped CollectionView but let me said the error was happening before with the previous XF version but only in iOS 12.4. Now it's exploiting on any iOS version.
If i remove the line 43 in MainPageViewModel.cs file the app works properly, but a i need to recover here some info before the service method has been called.
No break
Breaks the app with the following exception
{Invalid update: invalid number of sections. The number of sections contained in the collection view after the update (1) must be equal to the number of sections contained in the collection view before the update (1), plus or minus the number of sections inserted or deleted (1 inserted, 0 deleted).}

I have upload a new GitHub repo
No workaround
I am having the same issue after update to Xamarin.Forms 4.5.0.356. I am using iOS 13.3 and Grouped CollectionView. For me it's crashing on .Add method of the ObservableCollection
Objective-C exception thrown. Name: NSInternalInconsistencyException Reason: Invalid update: invalid number of sections. The number of sections contained in the collection view after the update (2) must be equal to the number of sections contained in the collection view before the update (2), plus or minus the number of sections inserted or deleted (1 inserted, 0 deleted).
Native stack trace:
0 CoreFoundation 0x00007fff23c7127e __exceptionPreprocess + 350
1 libobjc.A.dylib 0x00007fff513fbb20 objc_exception_throw + 48
2 CoreFoundation 0x00007fff23c70ff8 +[NSException raise:format:arguments:] + 88
3 Foundation 0x00007fff256e9b51 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 191
4 UIKitCore 0x00007fff47886dd0 -[UICollectionView _endItemAnimationsWithInvalidationContext:tentativelyForReordering:animator:] + 17849
5 UIKitCore 0x00007fff47881d49 -[UICollectionView _updateSections:updateAction:] + 449
6 UIKitCore 0x00007fff47881e65 -[UICollectionView insertSections:] + 64
7 App.iOS 0x000000010dc02bf9 xamarin_dyn_objc_msgSend + 217
8 ??? 0x000000011d659710 0x0 + 4788164368
hey @Reveon maybe you could try my suggestion I posted on a similar issue here : https://github.com/xamarin/Xamarin.Forms/issues/6011#issuecomment-559017278 it should fix the add problem.
Yeah, the suggested fix seem have helped to someone, but in my case:
a) I need to have Insert, not Add (which is kind of solvable because if the index which can be found out) (I suppose), but the example from #6011 haven't worked for me anyways. (Still receiving the exception on AddRange called.
Had the same issue before (had to stop "clearing" the collection, and had to add/remove one by one) , now in XF 4.5 it doesn't work and can't find a solution/workaround.
My debug log:
2020-03-25 15:18:20.338 Xamarin.PreBuilt.iOS[452:67117] *** Assertion failure in -[UICollectionView _endItemAnimationsWithInvalidationContext:tentativelyForReordering:animator:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKitCore/UIKit-3901.4.5/UICollectionView.m:6772
[0:] Objective-C exception thrown. Name: NSInternalInconsistencyException Reason: Invalid update: invalid number of sections. The number of sections contained in the collection view after the update (2) must be equal to the number of sections contained in the collection view before the update (2), plus or minus the number of sections inserted or deleted (1 inserted, 0 deleted).
Native stack trace:
0 CoreFoundation 0x000000019a0d6a5c 7519E999-1053-3367-B9D5-8844F6D3BDC6 + 1227356
1 libobjc.A.dylib 0x0000000199dfdfa4 objc_exception_throw + 56
2 CoreFoundation 0x0000000199fd8e88 7519E999-1053-3367-B9D5-8844F6D3BDC6 + 188040
3 Foundation 0x000000019a40e654 7B1733B1-74C9-3A33-8A58-853B0A029826 + 554580
4 UIKitCore 0x000000019d9d9894 D7630067-7A00-3CB7-99E1-E7F6C55D85C5 + 2623636
5 UIKitCore 0x000000019d9d581c D7630067-7A00-3CB7-99E1-E7F6C55D85C5 + 2607132
6 UIKitCore 0x000000019d9d5930 D7630067-7A00-3CB7-99E1-E7F6C55D85C5 + 2607408
7 Xamarin.PreBuilt.iOS 0x00000001022c7328 do_icall + 360
8 Xamarin.PreBuilt.iOS 0x00000001022c5944 do_icall_wrapper + 296
9 Xamarin.PreBuilt.iOS 0x00000001022be718 interp_exec_method_full + 1660
10 Xamarin.PreBuilt.iOS 0x00000001022be9e0 interp_exec_method_full + 2372
...
89 Xamarin.PreBuilt.iOS 0x00000001022be9e0 interp_exec_method_full + 2372
90 Xamarin.PreBuilt.iOS 0x00000001022bd264 interp_runtime_invoke + 352
91 Xamarin.PreBuilt.iOS 0x000000010211f7b0 mono_jit_runtime_invoke + 904
92 Xamarin.PreBuilt.iOS 0x00000001021d4400 mono_runtime_try_invoke + 156
93 Xamarin.PreBuilt.iOS 0x00000001021d60a0 mono_runtime_invoke + 100
94 Xamarin.PreBuilt.iOS 0x0000000102083000 _ZL31native_to_managed_trampoline_35P11objc_objectP13objc_selectorPP11_MonoMethodj + 236
95 Xamarin.PreBuilt.iOS 0x000000010208769c -[__MonoMac_NSAsyncSynchronizationContextDispatcher xamarinApplySelector] + 48
96 Foundation 0x000000019a4bf224 7B1733B1-74C9-3A33-8A58-853B0A029826 + 1278500
97 CoreFoundation 0x000000019a054a00 7519E999-1053-3367-B9D5-8844F6D3BDC6 + 694784
98 CoreFoundation 0x000000019a054958 7519E999-1053-3367-B9D5-8844F6D3BDC6 + 694616
99 CoreFoundation 0x000000019a0540f0 7519E999-1053-3367-B9D5-8844F6D3BDC6 + 692464
100 CoreFoundation 0x000000019a04f23c 7519E999-1053-3367-B9D5-8844F6D3BDC6 + 672316
101 CoreFoundation 0x000000019a04eadc CFRunLoopRunSpecific + 464
102 GraphicsServices 0x00000001a3fef328 GSEventRunModal + 104
103 UIKitCore 0x000000019e15c63c UIApplicationMain + 1936
104 Xamarin.PreBuilt.iOS 0x00000001022c729c do_icall + 220
105 Xamarin.PreBuilt.iOS 0x00000001022c5944 do_icall_wrapper + 296
106 Xamarin.PreBuilt.iOS 0x00000001022be718 interp_exec_method_full + 1660
107 Xamarin.PreBuilt.iOS 0x00000001022be968 interp_exec_method_full + 2252
108 Xamarin.PreBuilt.iOS 0x00000001022be9e0 interp_exec_method_full + 2372
109 Xamarin.PreBuilt.iOS 0x00000001022be9e0 interp_exec_method_full + 2372
110 Xamarin.PreBuilt.iOS 0x00000001022be9e0 interp_exec_method_full + 2372
111 Xamarin.PreBuilt.iOS 0x00000001022bd264 interp_runtime_invoke + 352
112 Xamarin.PreBuilt.iOS 0x000000010211f7b0 mono_jit_runtime_invoke + 904
113 Xamarin.PreBuilt.iOS 0x00000001021d2be4 mono_runtime_invoke_checked + 148
114 Xamarin.PreBuilt.iOS 0x00000001021d9450 mono_runtime_try_invoke_array + 1284
115 Xamarin.PreBuilt.iOS 0x000000010217cb44 ves_icall_InternalInvoke + 1036
116 Xamarin.PreBuilt.iOS 0x000000010218f508 ves_icall_InternalInvoke_raw + 108
117 Xamarin.PreBuilt.iOS 0x00000001022c7228 do_icall + 104
118 Xamarin.PreBuilt.iOS 0x00000001022c5944 do_icall_wrapper + 296
119 Xamarin.PreBuilt.iOS 0x00000001022be718 interp_exec_method_full + 1660
120 Xamarin.PreBuilt.iOS 0x00000001022be968 interp_exec_method_full + 2252
121 Xamarin.PreBuilt.iOS 0x00000001022be968 interp_exec_method_full + 2252
122 Xamarin.PreBuilt.iOS 0x00000001022be968 interp_exec_method_full + 2252
123 Xamarin.PreBuilt.iOS 0x00000001022be9e0 interp_exec_method_full + 2372
124 Xamarin.PreBuilt.iOS 0x00000001022bd264 interp_runtime_invoke + 352
125 Xamarin.PreBuilt.iOS 0x000000010211f7b0 mono_jit_runtime_invoke + 904
126 Xamarin.PreBuilt.iOS 0x00000001021d2be4 mono_runtime_invoke_checked + 148
127 Xamarin.PreBuilt.iOS 0x00000001021d7fcc mono_runtime_exec_main_checked + 128
128 Xamarin.PreBuilt.iOS 0x0000000102103bfc mono_jit_exec + 376
129 Xamarin.PreBuilt.iOS 0x00000001022baf88 xamarin_main + 2176
130 Xamarin.PreBuilt.iOS 0x00000001020cbd20 main + 84
131 libdyld.dylib 0x0000000199ed8360 7B531A15-3E73-3185-90E2-B88D9476DA5E + 4960
: Error - GetUsefulList - : {0}
=================================================================
Native Crash Reporting
=================================================================
Got a SIGSEGV while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries
used by your application.
=================================================================
=================================================================
Native stacktrace:
=================================================================
0x102118bb0 - /private/var/containers/Bundle/Application/B85F0E7B-EC9C-4B1A-8AE4-591EF0582F33/ToGuests.iOS.app/Xamarin.PreBuilt.iOS : mono_dump_native_crash_info
0x10210f550 - /private/var/containers/Bundle/Application/B85F0E7B-EC9C-4B1A-8AE4-591EF0582F33/ToGuests.iOS.app/Xamarin.PreBuilt.iOS : mono_handle_native_crash
0x10211c4e8 - /private/var/containers/Bundle/Application/B85F0E7B-EC9C-4B1A-8AE4-591EF0582F33/ToGuests.iOS.app/Xamarin.PreBuilt.iOS : mono_sigsegv_signal_handler_debug
0x199de4894 - /usr/lib/system/libsystem_platform.dylib : <redacted>
0x1022be9e0 - /private/var/containers/Bundle/Application/B85F0E7B-EC9C-4B1A-8AE4-591EF0582F33/ToGuests.iOS.app/Xamarin.PreBuilt.iOS : interp_exec_method_full
0x199fab000 - /System/Library/Frameworks/CoreFoundation.fr
amework/CoreFoundation : __dso_handle
=================================================================
Basic Fault Address Reporting
=================================================================
Memory around native instruction pointer (0x1022be978):0x1022be968 a8 83 58 f8 08 01 40 f9 68 87 00 f8 a8 03 57 f8 [email protected]
.....W.
0x1022be978 08 01 40 b9 a8 26 03 35 a8 02 40 79 c8 7a 68 f8 ..@..&[email protected].
.).@y
=================================================================
Managed Stacktrace:
=================================================================
at <unknown> <0xffffffff>
at UIKit.UIApplication:UIApplicationMain <0x000b0>
at UIKit.UIApplication:Main <0x0001e>
at UIKit.UIApplication:Main <0x00034>
at ToGuests.iOS.Application:Main <0x00012>
at <Module>:runtime_invoke_direct_void_string[] <0x00090>
at <unknown> <0xffffffff>
at System.Reflection.RuntimeMethodInfo:InternalInvoke <0x00034>
at System.Reflection.RuntimeMethodInfo:Invoke <0x000f6>
at System.Reflection.MethodBase:Invoke <0x0001a>
at Xamarin.PreBuilt.iOS.Applications:Main <0x0022c>
at <Module>:runtime_invoke_direct_void_string[] <0x00090>
=================================================================
0x1022be988 f9 03 15 aa 00 01 1f d6 35 13 00 91 a8 83 56 f8 ........5.....V.
0x1022be998 19 15 00 f9 08 05 40 f9 08 25 40 f9 29 07 40 79 ......@..%@
Regressed to "latest" Xamarin Forms 4.4 > 4.4.0.991864 and it works with no errors.
Had migrated the Android nuggets to AndroidX already, have to evaluate how to arrange this.
@hartez just to coordinate with our team. We have feature branches with latest XF4.5, we want to launch. Should we regress everything to XF4.4? Is there a workaround? Do you have an ETA for this issue?
Thanks in advance.
I face this issue for a while already, since the first versions of XF 4.4, updated to the latest XF 4.5 yesterday and it's still happening.
This is fixed in 4.6.0.
@hartez, I just checked here and it's indeed more stable on iOS, but I still face an internal inconsistency exception after updating to XF 4.6.
Objective-C exception thrown. Name: NSInternalInconsistencyException Reason: attempt to delete item 9 from section 3 which only contains 9 items before the update
Native stack trace:
0 CoreFoundation 0x00007fff23e39f0e __exceptionPreprocess + 350
1 libobjc.A.dylib 0x00007fff50ad79b2 objc_exception_throw + 48
2 CoreFoundation 0x00007fff23e39c88 +[NSException raise:format:arguments:] + 88
3 Foundation 0x00007fff258a3cd2 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 191
4 UIKitCore 0x00007fff4838ee5b -[UICollectionView _endItemAnimationsWithInvalidationContext:tentativelyForReordering:animator:] + 6475
5 UIKitCore 0x00007fff4839b0e6 -[UICollectionView _endUpdatesWithInvalidationContext:tentativelyForReordering:animator:] + 71
6 UIKitCore 0x00007fff4839b445 -[UICollectionView _performBatchUpdates:completion:invalidationContext:tentativelyForReordering:animator:] + 462
7 UIKitCore 0x00007fff4839b254 -[UICollectionView _performBatchUpdates:completion:invalidationContext:tentativelyForReordering:] + 90
8 UIKitCore 0x00007fff4839b1d7 -[UICollectionView _performBatchUpdates:completion:invalidationContext:] + 74
9 UIKitCore 0x00007fff4839b12c -[UICollectionView performBatchUpdates:completion:] + 53
Now idk whether that's the exact same issue... On Android it works perfectly.
I鈥檝e been doing some tests with XF 4.6.0 and it鈥檚 working properly with iOS 12.4 & 13.4 but I should test it with more data. Maybe tomorrow I鈥檒l update the attached repo.
Thank you in advance.
@hartez, I just checked here and it's indeed more stable on iOS, but I still face an internal inconsistency exception after updating to XF 4.6.
```
Objective-C exception thrown. Name: NSInternalInconsistencyException Reason: attempt to delete item 9 from section 3 which only contains 9 items before the updateNow idk whether that's the exact same issue...
@winterdouglas It looks like a different issue; the Reason part of the exception is different.
Please open a separate issue for your particular problem, along with a description of what you're doing when the exception is thrown (and your stack trace), and we'll look into it.
@hartez, yeah, I'll have to find clear reproduction steps for that. I'll take my time during the week to find out the exact conditions that are making that happen.
Thanks anyway!