Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CollectionViewHandler2 null reference exception if ItemsLayout is set for Tablet but NOT Phone #26065

Open
rysbilinski opened this issue Nov 22, 2024 · 0 comments
Labels
area-controls-collectionview CollectionView, CarouselView, IndicatorView p/2 Work that is important, but is currently not scheduled for release platform/iOS 🍎 potential-regression This issue described a possible regression on a currently supported version., verification pending t/bug Something isn't working

Comments

@rysbilinski
Copy link

rysbilinski commented Nov 22, 2024

Description

Adding a collectionview to a page and only setting the ItemsLayout property for Tablet will throw a null reference exception before the page appears on mobile.

Steps to Reproduce

  1. Add A collectionview to a page, and add the following to the collection view:

<CollectionView ItemsLayout="{OnIdiom Tablet='VerticalGrid 2'}" ItemsSource="{Binding Items}" VerticalOptions="Fill">

  1. Configure builder to use the new CollectionViewHandler2:
builder.ConfigureMauiHandlers(handlers =>
                {

                    handlers.AddHandler<Microsoft.Maui.Controls.CollectionView, Microsoft.Maui.Controls.Handlers.Items2.CollectionViewHandler2>();

                    handlers.AddHandler<Microsoft.Maui.Controls.CarouselView, Microsoft.Maui.Controls.Handlers.Items2.CarouselViewHandler2>();

                });
  1. Run the application on iOS
  2. Navigate to the page and you will see a crash in Program.cs

System.NullReferenceException: 'Object reference not set to an instance of an object.'

Link to public reproduction project repository

https://github.com/rysbilinski/CollectionViewHandler2Bugs

Version with bug

9.0.10 SR1

Is this a regression from previous behavior?

Yes, this used to work in .NET MAUI

Last version that worked well

8.0.100 SR10

Affected platforms

iOS

Affected platform versions

No response

Did you find any workaround?

Workaround was to add the "phone" OnIdiom parameter:

<CollectionView ItemsLayout="{OnIdiom Phone='VeritcalGrid', Tablet='VerticalGrid 2'}" ItemsSource="{Binding Items}" VerticalOptions="Fill">

Relevant log output

@rysbilinski rysbilinski added the t/bug Something isn't working label Nov 22, 2024
@samhouts samhouts added platform/iOS 🍎 potential-regression This issue described a possible regression on a currently supported version., verification pending area-controls-collectionview CollectionView, CarouselView, IndicatorView labels Nov 22, 2024
@PureWeen PureWeen added this to the .NET 9 Servicing milestone Nov 22, 2024
@PureWeen PureWeen added the p/2 Work that is important, but is currently not scheduled for release label Nov 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-controls-collectionview CollectionView, CarouselView, IndicatorView p/2 Work that is important, but is currently not scheduled for release platform/iOS 🍎 potential-regression This issue described a possible regression on a currently supported version., verification pending t/bug Something isn't working
Projects
Status: Todo
Development

No branches or pull requests

3 participants