maui
maui copied to clipboard
[iOS] NullReferenceException in TemplatedCell
Description
CollectionView crashes on iOS with the SR 2 release.
2024-02-15 10:44:10.513912+0100 AppName[14329:382545] System.NullReferenceException: Object reference not set to an instance of an object.
at Microsoft.Maui.Controls.Handlers.Items.TemplatedCell.UpdateSelectionColor()
at Microsoft.Maui.Controls.Handlers.Items.TemplatedCell.set_Selected(Boolean value)
2024-02-15 10:44:10.513983+0100 AppName[14329:382545] at UIKit.UICollectionView.DequeueReusableCell(NSString reuseIdentifier, NSIndexPath indexPath) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/build/dotnet/ios/generated-sources/UIKit/UICollectionView.g.cs:line 232
2024-02-15 10:44:10.514065+0100 AppName[14329:382545] at UIKit.UICollectionView.DequeueReusableCell(String reuseIdentifier, NSIndexPath indexPath) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/UIKit/UICollectionView.cs:line 23
2024-02-15 10:44:10.514142+0100 AppName[14329:382545] at Microsoft.Maui.Controls.Handlers.Items.ItemsViewController`1[[Microsoft.Maui.Controls.ReorderableItemsView, Microsoft.Maui.Controls, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].GetCell(UICollectionView collectionView, NSIndexPath indexPath)
2024-02-15 10:44:10.514208+0100 AppName[14329:382545] at UIKit.UIApplication.UIApplicationMain(Int32 argc, String[] argv, IntPtr principalClassName, IntPtr delegateClassName) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/UIKit/UIApplication.cs:line 58
2024-02-15 10:44:10.514260+0100 AppName[14329:382545] at UIKit.UIApplication.Main(String[] args, String principalClassName, String delegateClassName) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/UIKit/UIApplication.cs:line 84
at AppName.iOS.Application.Main(String[] args) in /Users/UserName/Documents/workspaces/zak-app/src/Zak/Platforms/iOS/Main.cs:line 17
Steps to Reproduce
I'm currently working on a reproduction sample, but I could reproduce the issue in a blank application yet.
Link to public reproduction project repository
No response
Version with bug
8.0.7 SR2
Is this a regression from previous behavior?
Yes, this used to work in .NET MAUI
Last version that worked well
8.0.6 SR1
Affected platforms
iOS
Affected platform versions
No response
Did you find any workaround?
Use 8.0.6 SR1
Relevant log output
No response
We've added this issue to our backlog, and we will work to address it as time and resources allow. If you have any additional information or questions about this issue, please leave a comment. For additional info about issue management, please read our Triage Process.
Will be fixed by https://github.com/dotnet/maui/tree/fix-20606
@naaeef can you try the latest nightly?
https://github.com/dotnet/maui/wiki/Nightly-Builds
Hi @naaeef. We have added the "s/needs-repro" label to this issue, which indicates that we require steps and sample code to reproduce the issue before we can take further action. Please try to create a minimal sample project/solution or code samples which reproduce the issue, ideally as a GitHub repo that we can clone. See more details about creating repros here: https://github.com/dotnet/maui/blob/main/.github/repro.md
This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.
This issue has been automatically marked as stale because it has been marked as requiring author feedback to reproduce the issue but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment. If it is closed, feel free to comment when you are able to provide the additional information and we will re-investigate.
I can see this issue on Mac as well
@jsuarezruiz @PureWeen I created a reproduction repo!
https://github.com/czmirek/mauiiOScollectionviewbug
Steps to repro:
- Run app on iPhone or on iPhone Simulator 15 17.2
- Click on Clear & Load items --- everything works.
- If you click now on Load items and select --- everything works.
Close the app and start debuggin again.
- Now click directly on "Load items and select"
- Boom.
Workaroud for this is:
#IF IOS
await Task.Delay(500);
#endif
Apparently it is some kind of racing condition bug, I was not able to find a better workaround.
This looks specific to being nested in a VSL
For now, do you need to nest your CollectionView inside a VerticalStackLayout?
Of course not, if the problem is CollectionView being inside VeritcalStackLayout I can use something else instead to position different UI elements under the CollectionView...like a Grid or CollectionView's footer.
Is placing CollectionView inside VeritcalStackLayout bad practice?