Skip to content
This repository was archived by the owner on May 1, 2024. It is now read-only.
This repository was archived by the owner on May 1, 2024. It is now read-only.

[Bug] NullReferenceException when displaying Toast or SnackBar #959

@maxkoshevoi

Description

@maxkoshevoi

Description

It's a bit tricky to reproduce, but I think it happens when you display toast and change page at the same time.

Here's how ViewModel displays the toast:

await Shell.Current?.CurrentPage?.DisplayToastAsync(LN.AutoupdateFailed);

And here's exception stack:

Xamarin.CommunityToolkit.UI.Views SnackBar.Show (Xamarin.Forms.Page sender, Xamarin.CommunityToolkit.UI.Views.Options.SnackBarOptions arguments)
Xamarin.CommunityToolkit.Extensions PageExtension.DisplayToastAsync (Xamarin.Forms.Page page, System.String message, System.Int32 durationMilliseconds)

Shell.Current.CurrentPage is not null before (since method gets called) and after (checked in catch block) DisplayToastAsync execution.

Update: It crashes on this line:
image
image

Steps to Reproduce

  1. Create Shell app with TabbBar and two tabs
  2. Create button on one of the tabs that executes this code:
await Shell.Current.GoToAsync("RouteToOtherTab");
try
{
    await Shell.Current.CurrentPage.DisplayToastAsync("");
}
catch (Exception ex)
{
    await Shell.Current.CurrentPage.DisplayAlert("Error", ex.ToString(), "Ok");
}
  1. Press the button

Expected Behavior

Displaying toast or snackbar doesn't throw exception

Actual Behavior

Displaying toast or snackbar throws exception

Basic Information

  • Version with issue: 1.0.3
  • Last known good version: -
  • IDE:
  • Platform Target Frameworks:
    • iOS:
    • Android: 11
    • UWP:
  • Android Support Library Version:
  • Nuget Packages:
  • Affected Devices:

Workaround

Wrap every DisplayToastAsync and DisplaySnackBarAsync in try-catch

Reproduction imagery

xct3

Reproduction Link

App7.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working. Breaky break.needs-more-discussionThis needs more discussion or info before discussing it as a proposal.not-up-for-grabsThis issue/PR is not up for grabs by the community but better handled by the maintainers

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions