[iOS] ObjCRuntime.RuntimeException in Microsoft.Maui.Platform.LayoutView during CollectionView layout changes on V2 #29599
Labels
area-controls-collectionview
CollectionView, CarouselView, IndicatorView
collectionview-cv2
platform/ios
s/needs-info
Issue needs more info from the author
s/no-repro
Can no longer be reproduced on latest
s/triaged
Issue has been reviewed
t/bug
Something isn't working
Description
A ObjCRuntime.RuntimeException occurs on iOS when interacting with the page, which uses CollectionView V2. The crash happens inconsistently, often after the layout resize. The error indicates a failure to marshal an Objective-C object of type Microsoft_Maui_Platform_LayoutView (address 0x170efa840) because the managed type Microsoft.Maui.Platform.LayoutView lacks a constructor accepting a NativeHandle parameter. This leads to a failure in accessing the Superview property during LayoutSubviews, likely due to invalid state references after changing the ItemsLayout in the CollectionView. The MAUI 9.0.70 release notes mention fixes for Header/Footer issues after ItemsLayout changes, which do not address this.
In my example, I have a Page with an Expander in the CollectionView.Header. When this view expands or collapses (e.g., on a tap), the header size changes. With CollectionView V1, the items shift down appropriately. With CollectionView V2 it crashes under two conditions: After leaving the page idle for some time and then resizing the header or when rapidly tapping the Expander multiple times in quick succession
Screen.Recording.2025-05-20.at.3.07.47.PM.mp4
Steps to Reproduce
Link to public reproduction project repository
https://github.com/billreiss/CollectionViewOverlappingIssue
Version with bug
9.0.70 SR7
Is this a regression from previous behavior?
No, this is something new
Last version that worked well
Unknown/Other
Affected platforms
iOS
Affected platform versions
iOS 18.5
Did you find any workaround?
Disable CollectionView V2 by commenting out or removing:
handlers.AddHandler<Microsoft.Maui.Controls.CollectionView,Microsoft.Maui.Controls.Handlers.Items2.CollectionViewHandler2>();
This reverts to the legacy CollectionViewHandler (V1), which handles header size changes correctly on iOS.
Relevant log output
The text was updated successfully, but these errors were encountered: