Closed jbe2277 closed 1 year ago
We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.
I'm also experiencing this error. In my testing it seems like the error only happens on iOS and specifically affects Collection Views with Grouped data when you clear the observable collection then add an item. You can see that it has to do with the collection view grouping in my test repository by toggling the CollectionView's IsGrouped
value.
Steps to Reproduce:
IsGrouped = true
then the app will crash. Experiencing the same issue just on iOS with a grouped CollectionView bound to an ObservableCollection.
+1 Also experiencing this
+1 Same issue for me on iOS (but no issue on Android)
Native stack trace:
0 CoreFoundation 0x00007ff8004278cb __exceptionPreprocess + 242
1 libobjc.A.dylib 0x00007ff80004dba3 objc_exception_throw + 48
2 Foundation 0x00007ff800b8637c _userInfoForFileAndLine + 0
3 UIKitCore 0x0000000116fcf525 -[UICollectionView _endItemAnimationsWithInvalidationContext:tentativelyForReordering:animator:collectionViewAnimator:] + 13198
4 UIKitCore 0x0000000116fcad2b -[UICollectionView _updateSections:updateAction:] + 402
5 UIKitCore 0x0000000116fcadf7 -[UICollectionView insertSections:] + 64
6 libxamarin-dotnet-debug.dylib 0x0000000107fb1379 xamarin_dyn_objc_msgSend + 217
7 ??? 0x000000011dd66ca7 0x0 + 4795559079
8 libmonosgen-2.0.dylib 0x000000010881a43a ves_pinvoke_method + 474
9 libmonosgen-2.0.dylib 0x000000010880c6cc interp_exec_method + 3692
10 libmonosgen-2.0.dylib 0x0000000108809e93 interp_runtime_invoke + 259
11 libmonosgen-2.0.dylib 0x00000001086309ad mono_runtime_try_invoke + 157
12 libmonosgen-2.0.dylib 0x0000000108632b3f mono_runtime_invoke + 95
13 xxx.Maui 0x0000000105798fe8 _ZL30native_to_managed_trampoline_9P11objc_objectP13objc_selectorPP11_MonoMethodj + 280
14 xxx.Maui 0x00000001057997e9 -[__MonoMac_NSAsyncActionDispatcher xamarinApplySelector] + 41
15 Foundation 0x00007ff800c7f5f7 __NSThreadPerformPerform + 177
16 CoreFoundation 0x00007ff800387035 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
17 CoreFoundation 0x00007ff800386f74 __CFRunLoopDoSource0 + 157
18 CoreFoundation 0x00007ff8003867d1 __CFRunLoopDoSources0 + 308
19 CoreFoundation 0x00007ff800380e73 __CFRunLoopRun + 927
20 CoreFoundation 0x00007ff8003806f7 CFRunLoopRunSpecific + 560
21 GraphicsServices 0x00007ff809c5c28a GSEventRunModal + 139
22 UIKitCore 0x0000000117aac62b -[UIApplication _run] + 994
23 UIKitCore 0x0000000117ab1547 UIApplicationMain + 123
24 libxamarin-dotnet-debug.dylib 0x0000000107f6ba5a xamarin_UIApplicationMain + 58
25 libmonosgen-2.0.dylib 0x000000010881b609 do_icall + 345
26 libmonosgen-2.0.dylib 0x000000010881a113 do_icall_wrapper + 291
27 libmonosgen-2.0.dylib 0x000000010880c52c interp_exec_method + 3276
28 libmonosgen-2.0.dylib 0x0000000108809e93 interp_runtime_invoke + 259
29 libmonosgen-2.0.dylib 0x000000010862eef8 mono_runtime_invoke_checked + 136
30 libmonosgen-2.0.dylib 0x0000000108636f0c do_exec_main_checked + 92
31 libmonosgen-2.0.dylib 0x0000000108765ec2 mono_jit_exec + 354
32 libxamarin-dotnet-debug.dylib 0x0000000107fafe77 xamarin_main + 1927
33 xxxx.Maui 0x000000010582ca44 main + 52
34 dyld 0x00000001060782bf start_sim + 10
35 ??? 0x000000010675752e 0x0 + 4403328302
I've also seen this crash. Wrapping the Adding of items within a MainThread.InvokeOnMainThreadAsync
seems to work around this crash for me. YMMV.
I've also seen this crash. Wrapping the Adding of items within a
MainThread.InvokeOnMainThreadAsync
seems to work around this crash for me. YMMV.
Does not work for me. Also, does not work on the sample provided by @EthanHipps
I've also seen this crash. Wrapping the Adding of items within a
MainThread.InvokeOnMainThreadAsync
seems to work around this crash for me. YMMV.Does not work for me. Also, does not work on the sample provided by @EthanHipps
I hadn't tried the sample earlier. The following works for me as a work-around in that sample:
[RelayCommand]
private async Task ClearAndAddItemsAsync()
{
TestData.Clear();
await Task.Delay(100);
TestData.Add(new("Header 1", Data));
}
The main change being adding a delay between clearing the list and adding new items.
I'm using ObservableRangeCollection from MvvmHelpers. So I cannot do this kind of hack easily. Is this issue going to be fixed soon ?
+1 this is becoming a big issue for us
My workaround for now is to add the group headers as items to the list and use a datatemplateselector.
Alternatively set a boolean on the first item of each group and create a template for first items that includes the group header template. That way the length of the list is not modified if that matters.
I had a similar crash. My workaround was just to recreate the ObservableCollection fresh rather than clearing and adding.
Same problem here and it looks like this is an inherited problem from Xamarin Forms. I don't have this issue if I use a CollectionView
without grouping my data. If I do group it, my app ends up crashing.
Same problem as @imsam67
Any solution yet? I get the error when adding items to an ObservableCollection that is bound to a ListView. Using MVVM helper and adding items using the .AddRange() method. Using MVVM in .Net MAUI. Works fine in Windows and on Android.
I solved this problem by making the collection a type that inherits from an ObservableObject, any changes to the object will then change in the collection.
Hi Ian. Could you please elaborate on what you did. Did you create a class that inherited from ObservableObject or from ObservableRangeCollection?
Yes, I created a class eg Monkey
which inherits ObservableObject
then created an ObservableCollection<Monkey>
Doesn't work for me, same error as before :(
Unfortunately, the bug still occurs with the latest MAUI version.
Environment:
How to reproduce:
Note: It works correct on:
Output:
ObjCRuntime.ObjCException
Message=Objective-C exception thrown. Name: NSInternalInconsistencyException Reason: Invalid batch updates detected: the number of sections and/or items returned by the data source before and/or after performing the batch updates are inconsistent with the updates.
Data source before updates = { 9 sections with item counts: [1, 1, 1, 1, 1, 1, 1, 1, 2] }
Data source after updates = { 9 sections with item counts: [1, 1, 1, 1, 1, 1, 1, 1, 2] }
Updates = [
Insert section 0
]
Collection view: <UICollectionView: 0x15a366200; frame = (0 0; 2388 1480); clipsToBounds = YES; autoresize = W+H; gestureRecognizers = <NSArray: 0x280a40540>; backgroundColor = UIExtendedGrayColorSpace 0 0; layer = <CALayer: 0x280ef66e0>; contentOffset: {0, 0}; contentSize: {2388, 975}; adjustedContentInset: {0, 0, 0, 0}; layout: <Microsoft_Maui_Controls_Handlers_Items_ListViewLayout: 0x153fd06e0>; dataSource: <Microsoft_Maui_Controls_Handlers_Items_ReorderableItemsViewController_1: 0x153fce370>>
Native stack trace:
0 CoreFoundation 0x000000019313ada0 6A07CBE8-4F65-3DBC-B59D-C1A188A7B95D + 40352
1 libobjc.A.dylib 0x000000018c2643d0 objc_exception_throw + 60
2 Foundation 0x000000018d9596cc 35567930-FBC2-374B-B44B-1DDFE3ADA4A1 + 5117644
3 UIKitCore 0x00000001958a1358 B0858D8E-7220-37BF-873F-ECC2B0A358C3 + 7349080
4 UIKitCore 0x00000001954ac5ec B0858D8E-7220-37BF-873F-ECC2B0A358C3 + 3200492
5 UIKitCore 0x000000019540c994 B0858D8E-7220-37BF-873F-ECC2B0A358C3 + 2546068
6 UIKitCore 0x000000019540c854 B0858D8E-7220-37BF-873F-ECC2B0A358C3 + 2545748
7 NewsReader.MauiSystem 0x00000001050c30b4 _ZN16XamarinCallState3selEv + 3468
8 NewsReader.MauiSystem 0x000000010506942c _ZN7plcrash2MS5async24dwarf_cfa_state_iteratorIyxE4nextEPjPNS1_28plcrash_dwarf_cfa_reg_rule_tEPy + 83248
9 NewsReader.MauiSystem 0x00000001054272e8 _ZNK3icu6number23NumberFormatterSettingsINS0_24LocalizedNumberFormatterEE10toSkeletonER10UErrorCode + 2740128
10 NewsReader.MauiSystem 0x000000010541ca6c _ZNK3icu6number23NumberFormatterSettingsINS0_24LocalizedNumberFormatterEE10toSkeletonER10UErrorCode + 2696996
11 NewsReader.MauiSystem 0x000000010541a544 _ZNK3icu6number23NumberFormatterSettingsINS0_24LocalizedNumberFormatterEE10toSkeletonER10UErrorCode + 2687484
12 NewsReader.MauiSystem 0x00000001053e2650 _ZNK3icu6number23NumberFormatterSettingsINS0_24LocalizedNumberFormatterEE10toSkeletonER10UErrorCode + 2458376
13 NewsReader.MauiSystem 0x0000000105320134 _ZNK3icu6number23NumberFormatterSettingsINS0_24LocalizedNumberFormatterEE10toSkeletonER10UErrorCode + 1662444
14 NewsReader.MauiSystem 0x0000000105323b28 _ZNK3icu6number23NumberFormatterSettingsINS0_24LocalizedNumberFormatterEE10toSkeletonER10UErrorCode + 1677280
15 NewsReader.MauiSystem 0x000000010545fae4 _ZNK3icu6number23NumberFormatterSettingsINS0_24LocalizedNumberFormatterEE10toSkeletonER10UErrorCode + 2971548
16 NewsReader.MauiSystem 0x000000010546d138 _ZNK3icu6number23NumberFormatterSettingsINS0_24LocalizedNumberFormatterEE10toSkeletonER10UErrorCode + 3026416
17 Foundation 0x000000018d4b389c 35567930-FBC2-374B-B44B-1DDFE3ADA4A1 + 243868
18 CoreFoundation 0x0000000193204208 6A07CBE8-4F65-3DBC-B59D-C1A188A7B95D + 864776
19 CoreFoundation 0x0000000193210864 6A07CBE8-4F65-3DBC-B59D-C1A188A7B95D + 915556
20 CoreFoundation 0x00000001931956c8 6A07CBE8-4F65-3DBC-B59D-C1A188A7B95D + 411336
21 CoreFoundation 0x00000001931ab1c4 6A07CBE8-4F65-3DBC-B59D-C1A188A7B95D + 500164
22 CoreFoundation 0x00000001931b04dc CFRunLoopRunSpecific + 612
23 GraphicsServices 0x00000001cdb1f35c GSEventRunModal + 164
24 UIKitCore 0x000000019553c37c B0858D8E-7220-37BF-873F-ECC2B0A358C3 + 3789692
25 UIKitCore 0x000000019553bfe0 UIApplicationMain + 340
26 NewsReader.MauiSystem 0x0000000105080714 xamarin_UIApplicationMain + 60
27 NewsReader.MauiSystem 0x0000000105428274 _ZNK3icu6number23NumberFormatterSettingsINS0_24LocalizedNumberFormatterEE10toSkeletonER10UErrorCode + 2744108
28 NewsReader.MauiSystem 0x0000000105426f94 _ZNK3icu6number23NumberFormatterSettingsINS0_24LocalizedNumberFormatterEE10toSkeletonER10UErrorCode + 2739276
29 NewsReader.MauiSystem 0x000000010541c970 _ZNK3icu6number23NumberFormatterSettingsINS0_24LocalizedNumberFormatterEE10toSkeletonER10UErrorCode + 2696744
30 NewsReader.MauiSystem 0x000000010541a544 _ZNK3icu6number23NumberFormatterSettingsINS0_24LocalizedNumberFormatterEE10toSkeletonER10UErrorCode + 2687484
31 NewsReader.MauiSystem 0x00000001053e2650 _ZNK3icu6number23NumberFormatterSettingsINS0_24LocalizedNumberFormatterEE10toSkeletonER10UErrorCode + 2458376
32 NewsReader.MauiSystem 0x0000000105320134 _ZNK3icu6number23NumberFormatterSettingsINS0_24LocalizedNumberFormatterEE10toSkeletonER10UErrorCode + 1662444
33 NewsReader.MauiSystem 0x0000000105327d44 _ZNK3icu6number23NumberFormatterSettingsINS0_24LocalizedNumberFormatterEE10toSkeletonER10UErrorCode + 1694204
34 NewsReader.MauiSystem 0x00000001053e8760 _ZNK3icu6number23NumberFormatterSettingsINS0_24LocalizedNumberFormatterEE10toSkeletonER10UErrorCode + 2483224
35 NewsReader.MauiSystem 0x00000001050c2110 xamarin_get_original_working_directory_path + 4016
36 NewsReader.MauiSystem 0x000000010545aa04 _ZNK3icu6number23NumberFormatterSettingsINS0_24LocalizedNumberFormatterEE10toSkeletonER10UErrorCode + 2950844
37 dyld 0x00000001b2628dec 41605DC7-F412-37D1-B51B-FEE1A26701E9 + 89580
Source=<unknown>
StackTrace:
at UIKit.UICollectionView.InsertSections(NSIndexSet sections)
at Microsoft.Maui.Controls.Handlers.Items.ObservableGroupedSource.<>c__DisplayClass29_0.<Add>b__0()
at Microsoft.Maui.Controls.Handlers.Items.ObservableGroupedSource.Update(Action update)
at Microsoft.Maui.Controls.Handlers.Items.ObservableGroupedSource.Add(NotifyCollectionChangedEventArgs args)
at Microsoft.Maui.Controls.Handlers.Items.ObservableGroupedSource.CollectionChanged(NotifyCollectionChangedEventArgs args)
at Microsoft.Maui.Controls.Handlers.Items.ObservableGroupedSource.<>c__DisplayClass24_0.<CollectionChanged>b__0()
at Foundation.NSAsyncActionDispatcher.Apply()
at UIKit.UIApplication.UIApplicationMain(Int32 argc, String[] argv, IntPtr principalClassName, IntPtr delegateClassName)
at UIKit.UIApplication.Main(String[] args, Type principalClass, Type delegateClass)
at Waf.NewsReader.MauiSystem.Platforms.iOS.Program.Main(String[] args) in C:\Dev\GitHub\waf\src\NewsReader\NewsReader.MauiSystem\Platforms\iOS\Program.cs:line 9
Neither invoking on main thread or adding a delay between the clear and add worked for me. But swapping the entire groups collection did. I just implemented it as a notifying property.
List<MyGroup> groups;
public List<MyGroup> Groups { get => groups; set => SetProperty(ref groups, value); }
Then replace the entire List with another one that contains the new groups.
It may also work if you manipulate your observable collection directly via the Items property and then manually fire the change event.
It seems this is a new exception in iOS 16.4, plenty of Swift devs are reporting the same problem.
Hello lovely human, thank you for your comment on this issue. Because this issue has been closed for a period of time, please strongly consider opening a new issue linking to this issue instead to ensure better visibility of your comment. Thank you!
Description
I get the following crash after adding items to an ObservableCollection for the NewsReader app.
Related: https://github.com/dotnet/maui/issues/4756 (Maybe this commit did not solve all cases: https://github.com/dotnet/maui/commit/cf2d2cd075365ab902d7998d75259f34c5c75853)
Crash:
Steps to Reproduce
Link to public reproduction project repository
https://github.com/jbe2277/waf/tree/5a957034c1d92f45402c2069e180fecdc54873d0
Version with bug
6.0.486 (current)
Last version that worked well
Unknown/Other
Affected platforms
iOS
Affected platform versions
iOS 15
Did you find any workaround?
No
Relevant log output
No response