【问题标题】:Xamarin Forms MasterDetail page navigation causing crash on android [Fatal signal 6 (SIGABRT), code -6], Works on iOS and UWPXamarin Forms MasterDetail 页面导航导致 android [致命信号 6 (SIGABRT),代码 -6] 崩溃,适用于 iOS 和 UWP
【发布时间】:2017-08-16 20:33:06
【问题描述】:

我有一个如下所示的主详细信息

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

League Page(Master)设计有一个如下的列表视图

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

后面的代码是

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);   
    }
}

在 LeaguesViewModel 中,我让 SelectedLeague 属性设置器更新详细信息页面并像这样隐藏 Master

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;
        }
    }
}

这似乎有时像我希望的那样工作。它导航到新的 DivisionsPage 并隐藏 master。似乎在 iOS 和 UWP 上运行良好,但在 Android 上崩溃了以下

[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

如果需要更多详细信息,请告诉我,谢谢!

【问题讨论】:

  • 能否分享一个可以重现此问题的基本演示?
  • @ElvisXia-MSFT 这是一个简化版本,但我已经能够在这里重现问题bitbucket.org/schnabs/clubapp_42990427 要回购一定要使用 android 并在循环中继续点击打开主控,然后选择从列表中,打开主,从主列表中选择等等,直到它崩溃
  • 我发现另一个人有这个问题bugzilla.xamarin.com/show_bug.cgi?id=54120 另外我认为这是它来自单声道github.com/mono/mono/blob/master/mono/metadata/…
  • 我也有同样的问题!
  • 在我的情况下,我也使用主从。在我的详细信息中,我有一个 ListView,它导航到另一个具有 ListView 的页面。当我回去时,有时应用程序会崩溃并显示完全相同的消息。我正在使用 Xamarin 表单

标签: android xamarin mvvm xamarin.forms master-detail


【解决方案1】:

我已将您的示例更新到最新版本的 2.3.4,它可以在 Android 上运行而没有问题。我建议您删除 MasterDetailPage 中的代码并将其更新为以下内容:

<?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>

【讨论】:

  • 您使用 Xamarin Forms 解决了该错误(我没有测试您的解决方案)。该错误也存在于(本机)Xamarin Android 应用程序中。你有针对这种情况的解决方案吗?
  • 您没有发布非表单复制品。如果您的问题与表单应用有关,那么根据您的示例,您应该只需要更新到最新的稳定版本。
  • 我不是 OP(但我开始了赏金)。我只是在使用非表单应用程序时遇到了同样的问题,我想您可能知道可以转移到我的案例的潜在问题。
  • 如果你发一个repro我可以看看
  • 这里是一个示例应用程序:drive.google.com/open?id=0B7De5DfDEi--QlJEN29xNjhDZGc 来回运行 17 次后它崩溃(我的 Lg G4c 为 17 次,而 Galaxy S6 为 30 次,但数量始终相同)。
【解决方案2】:

我有一个类似的问题,原来是由 NavigationPage 的 android 渲染器中的错误引起的。 看看这个thread at the Xamarin Forum 有一个链接的错误报告和一个解决方法。该问题应在当前 XamForms 版本中得到解决。

您可以尝试省略 NavigationPage(并将您的 DivisionsPage 直接设置为 Detail)以查明是否是导致崩溃的 NavigationPage。

【讨论】:

    猜你喜欢
    • 2014-04-29
    • 1970-01-01
    • 1970-01-01
    • 2016-01-05
    • 1970-01-01
    • 2014-12-21
    • 2014-06-25
    • 2021-04-22
    • 2020-05-01
    相关资源
    最近更新 更多