Forum Xamarin.Forms
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

Why is my app crashing on page load?

MatthewWarrMatthewWarr USMember ✭✭
edited October 4 in Xamarin.Forms

I have an app that until very recently was working ok, but now it is crashing when trying to push a new page. I am using XAML with CodeBehind and an MVVM approach.

I have a ListView which a user taps and entry on that should take them to the next page.

        async void Handle_ItemTapped(object sender, Xamarin.Forms.ItemTappedEventArgs e)
        {
            if (e.Item == null)
                return;
            var race = e.Item as Race;

            await Navigation.PushAsync(new OnePage(race));
            //Deselect Item
            ((ListView)sender).SelectedItem = null;
        }

I can put a breakpoint on await Navigation.PushAsync(new OnePage(race));, step into the page constructor, step through every line in the page constructor which takes me into loading a view model.

public OnePage(Race race)
        {
            InitializeComponent();


            var viewModel = new OnePageViewModel(this, race);

            BindingContext = viewModel;
        }

Step through every line in the view model until it returns me to the code behind, which returns me back to the original await Navigation.PushAsync(new OnePage(race)); and the app crashes, totally freezes in the simulator (iOS and Android) and I have to stop the project in VS - before doing whatever it is meant to do next (which I am not sure about, as it should just load the page, there is no more of my code to execute).

I have emptied the XAML to ensure its not a problem with the XAML itself and narrowed it down to this section. Commenting it out makes the page load fine.

                <CollectionView.ItemsLayout>
                    <GridItemsLayout Orientation="Vertical" Span="4" />
                </CollectionView.ItemsLayout>

Using Xamarin 4.8 (latest NuGet) but have tried rolling back to all major versions to up to 4.4 in case its a collectionview issue. Can't put my finger on it.

The thing is, for the app to work the way I want it really needs to be the collectionview to give the required UI behaviour so don;t really have an alternative (That I can think of based upon the docs)

Any ideas?

Tagged:

Answers

  • LandLuLandLu Member, Xamarin Team Xamurai

    I didn't see someone reported GridItemsLayout would cause crashing.
    Have you tried to reduce the span?
    If you could reproduce it with a sample, try to report the issue here:
    https://github.com/xamarin/Xamarin.Forms/issues

  • MatthewWarrMatthewWarr USMember ✭✭

    I found an existing issue on GitHub. It is related to when the IsVisible state is manipulated. If you try and load the page with the collectionview visibility as false, then it crashes. In other parts os my code I am enabling and disabling this. It is in the vNext sprint for 5.0.0 so fingers crossed, in the meantime I am going to have to live with a non-ideal UI.

  • LandLuLandLu Member, Xamarin Team Xamurai
    edited October 8

    It is talking about issues on UWP.
    I haven't encountered this circumstance on Android or iOS before.
    If you have a sample to reproduce this issue, try to post it on the github.

Sign In or Register to comment.