Search code examples
androidxamarinmvvmxamarin.formsmaster-detail

Xamarin Forms MasterDetail page navigation causing crash on android [Fatal signal 6 (SIGABRT), code -6], Works on iOS and UWP


I have a Master Detail like below

public partial class LeaguesMDPage : MasterDetailPage
{
    public LeaguesMDPage()
    {
        InitializeComponent();
        Master = new LeaguesPage();
        Detail = new NavigationPage(new DivisionsPage(new League()));
    }
}

League Page (the Master) design has a list view like below

    <ListView
    ItemsSource="{Binding Leagues}"
    SelectedItem="{Binding SelectedLeague, Mode=TwoWay}"
    IsPullToRefreshEnabled="True"
    RefreshCommand="{Binding UpdateLeagues}"
    IsRefreshing="{Binding IsBusy}"
    >

and the code behind is

public partial class LeaguesPage : ContentPage
{
    LeaguesViewModel vm;

    public LeaguesPage()
    {
        InitializeComponent();
        BindingContext = vm = new LeaguesViewModel(this);
    }
    protected override void OnAppearing()
    {
        base.OnAppearing();
        vm.UpdateLeagues.Execute(false);   
    }
}

In the LeaguesViewModel I have the the SelectedLeague property setter update the Detail page and hide the Master like so

League _SelectedLeague;

public League SelectedLeague
{
    get { return _SelectedLeague; }
    set
    {
        _SelectedLeague = value;
        OnPropertyChanged();
        if (_SelectedLeague != null)
        {
            Debug.WriteLine($"Navigating to DivisionsPage with LeagueID {_SelectedLeague.ID}");
            var mdp = (MasterDetailPage)App.Current.MainPage;
            Device.OnPlatform(                     
                    Android: () => { mdp.IsPresented = false; },
                    iOS: () => { mdp.IsPresented = false; },
                    WinPhone: () => { },
                    Default: () => { mdp.IsPresented = false; }
                );
            mdp.Detail = new NavigationPage(new DivisionsPage(_SelectedLeague));
            _SelectedLeague = null;
        }
    }
}

This does seems to work as I hope sometimes. It Navigates to the new DivisionsPage and hides the master. Seems to work fine on iOS and UWP, but its crashing on Android with the following

[0:] Server Returned 34 divisions
[0:] Navigating to DivisionsPage with LeagueID 12
[0:] UpdatePoolRankings: Called GetDivisionsAsync
03-23 02:40:52.151 W/Mono    ( 6249): The request to load the assembly System.Core v4.0.0.0 was remapped to v2.0.5.0
03-23 02:40:52.151 D/Mono    ( 6249): Unloading image System.Core.dll [0x99db7700].
03-23 02:40:52.151 D/Mono    ( 6249): Image addref System.Core[0xaec169a0] -> System.Core.dll[0x9d166d00]: 11
03-23 02:40:52.151 D/Mono    ( 6249): Config attempting to parse: 'System.Core.dll.config'.
03-23 02:40:52.151 D/Mono    ( 6249): Config attempting to parse: '/Users/builder/data/lanes/4009/f3074d2c/source/monodroid/builds/install/mono-x86/etc/mono/assemblies/System.Core/System.Core.config'.
03-23 02:40:52.152 W/Mono    ( 6249): The request to load the assembly System.Core v4.0.0.0 was remapped to v2.0.5.0
03-23 02:40:52.152 D/Mono    ( 6249): Unloading image System.Core.dll [0x99db7700].
03-23 02:40:52.152 D/Mono    ( 6249): Image addref System.Core[0xaec169a0] -> System.Core.dll[0x9d166d00]: 12
03-23 02:40:52.152 D/Mono    ( 6249): Config attempting to parse: 'System.Core.dll.config'.
03-23 02:40:52.152 D/Mono    ( 6249): Config attempting to parse: '/Users/builder/data/lanes/4009/f3074d2c/source/monodroid/builds/install/mono-x86/etc/mono/assemblies/System.Core/System.Core.config'.
03-23 02:40:52.383 D/Mono    ( 6249): [0x9b5bf930] hill climbing, change max number of threads 4
[0:] Server Returned 3 divisions
03-23 02:40:52.421 F/        ( 6249): * Assertion at /Users/builder/data/lanes/4009/f3074d2c/source/mono/mono/metadata/sgen-tarjan-bridge.c:1139, condition `xref_count == xref_index' not met
03-23 02:40:52.421 F/libc    ( 6249): Fatal signal 6 (SIGABRT), code -6 in tid 6249 (ClubApp.Droid)
InspectorDebugSession(21): Disposed
InspectorDebugSession(21): HandleTargetEvent: TargetExited

Please let me know if more details are need, thanks!


Solution

  • I updated your sample to the latest release of 2.3.4 and it runs on Android without an issue. I would suggest that you remove the code behind in your MasterDetailPage and update it to the following:

    <?xml version="1.0" encoding="utf-8" ?>
    <MasterDetailPage xmlns="http://xamarin.com/schemas/2014/forms"
                 xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                 xmlns:local="clr-namespace:ClubApp.Views;assembly=ClubApp"
                 xmlns:model="clr-namespace:ClubApp.Models;assembly=ClubApp"
                 x:Class="ClubApp.Views.MainMasterDetailPage" 
                 Title="MD Page"
                 IsPresented="True">
        <MasterDetailPage.Master>
            <local:LeaguesPage />
        </MasterDetailPage.Master>
        <MasterDetailPage.Detail>
            <NavigationPage>
                <x:Arguments>
                    <local:DivisionsPage>
                        <x:Arguments>
                            <model:League />
                        </x:Arguments>
                    </local:DivisionsPage>
                </x:Arguments>
            </NavigationPage>
        </MasterDetailPage.Detail>
    </MasterDetailPage>