Forum Xamarin.Forms

Announcement:

The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

Xamarin Shell - Selecting the 3rd tab in FlyoutItem causes crash (Shell_UWP_Experimental)

I had already posted this, but it disappeared ?!
Apologies if this isn't the right place to post this and/or my format isn't correct.

I created a new Xamarin.Forms project using the flyout template.
Then, I followed the instructions @ [docs.microsoft.com/en-us/xamarin/xamarin-forms/platform/windows/installation] to add a UWP project (Im, not allowed to post links, new user =P).
Then I added the xaml (below) in AppShell.xaml (Xamarin.Forms project).

When I run the project all seems to work right, but when I'm clicking through the menu elements (below), as soon as I click the 3rd element (regardless of the order), the application crashes with "The operation attempted to access data outside the valid range" in the UnhandledException exception handler in the generated App.g.i.cs file. No further details are given, not even a stack trace (crash was probably in native code).

I get the same behavior if I add the menu elements at runtime (Shellcontent wrapped in a Tab, multiple tabs wrapped in a FlyoutItem with AsMultipleItems set as the FlyoutDisplayOptions).

XAmarin.Forms Version: 4.8.0.1534
I can include the project if required.

<FlyoutItem FlyoutDisplayOptions="AsMultipleItems">
    <Tab Title="1">
        <ShellContent>
            <local:AboutPage />
        </ShellContent>
    </Tab>
    <Tab Title="2">
        <ShellContent>
            <local:ItemDetailPage />
        </ShellContent>
    </Tab>
    <Tab Title="3">
        <ShellContent>
            <local:ItemsPage />
        </ShellContent>
    </Tab>
    <Tab Title="4">
        <ShellContent>
            <local:LoginPage />
        </ShellContent>
    </Tab>
    <Tab Title="5">
        <ShellContent>
            <local:NewItemPage />
        </ShellContent>
    </Tab>
</FlyoutItem>

Posts

  • XArtur0XArtur0 Member ✭✭
    edited October 2020

    I enabled mixed debugging and loaded the symbols for Windows.UI.Xaml.dll and managed to get a stack trace.

    It seems the issue happens somewhere in the native code of the FlyoutItem indeed, probably not a race condition because it's always on the 3rd item click.

    As a temporary work around I added a new UnhandledException handler in the App constructor in App.xaml.cs, added the DISABLE_XAML_GENERATED_BREAK_ON_UNHANDLED_EXCEPTION symbol on the Debug configuration, and then I just mark the exception as handled whenever its thrown.

            UnhandledException += (sender, e) =>
            {
                var msg = "attempted to access data outside the valid range";
    
                if (e.Message.Contains(msg, StringComparison.OrdinalIgnoreCase))
                {
                    e.Handled = true;
                }
                else
                {
                    if (System.Diagnostics.Debugger.IsAttached) 
                        System.Diagnostics.Debugger.Break();
                }
            };
    

    It seems to work (i.e. app doesnt crash, the view loads correctly), but who knows if memory is being leaked, states is being corrupted or any other nasties in the native code...

    I wonder if I should make a bug report, and if so where. Xamarin github?

  • Nor0xNor0x USMember ✭✭

    @XArtur0 i have the same issue - i guess the correct place to report it would be the Xamarin.Forms Repository on Github. Did you find out more about this crash yet?

Sign In or Register to comment.