This repository was archived by the owner on May 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 459
This repository was archived by the owner on May 1, 2024. It is now read-only.
[Bug] NullReferenceException when displaying Toast or SnackBar #959
Copy link
Copy link
Closed
Labels
bugSomething isn't working. Breaky break.Something isn't working. Breaky break.needs-more-discussionThis needs more discussion or info before discussing it as a proposal.This 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 maintainersThis issue/PR is not up for grabs by the community but better handled by the maintainers
Description
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:
Steps to Reproduce
- Create Shell app with TabbBar and two tabs
- 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");
}
- 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
Reproduction Link
Metadata
Metadata
Assignees
Labels
bugSomething isn't working. Breaky break.Something isn't working. Breaky break.needs-more-discussionThis needs more discussion or info before discussing it as a proposal.This 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 maintainersThis issue/PR is not up for grabs by the community but better handled by the maintainers