Repository navigation
Closed
Labels
Description
Is there an existing issue for this?
- I have searched the existing issues
Did you read the "Reporting a bug" section on Contributing file?
- I have read the "Reporting a bug" section on Contributing file: https://github.com/CommunityToolkit/Maui/blob/main/CONTRIBUTING.md#reporting-a-bug
Current Behavior
In my app I have a Help page in which I use a popup to show a "loading" state of the app while the app is uploading logs and stuff to my backend. As soon as this is done, the loading popup is hidden and also Disposed. In the next step, my app opens via Browser.LaunchAsync a contact form for the user to fill in details. On Android everything works fine. On iOS however it crashes with the following NullReferenceException when pressing the "Done" button of said Browser.
System.NullReferenceException: Object reference not set to an instance of an object.
at CommunityToolkit.Maui.Core.Views.MauiPopup.SetShadowView(UIView& target) in /_/src/CommunityToolkit.Maui.Core/Views/Popup/MauiPopup.macios.cs:line 161
at CommunityToolkit.Maui.Core.Views.MauiPopup.ViewDidLayoutSubviews() in /_/src/CommunityToolkit.Maui.Core/Views/Popup/MauiPopup.macios.cs:line 52
at CommunityToolkit.Maui.Core.Views.MauiPopup.__Registrar_Callbacks__.callback_22_CommunityToolkit_Maui_Core_Views_MauiPopup_ViewDidLayoutSubviews(IntPtr pobj, IntPtr sel, IntPtr* exception_gchandle)
This is a breakdown of my app code for that:
if (UploadExtendedReport)
{
LoadingPopup? loadingPopup = null; //this is a Toolkit Popup
try
{
loadingPopup = new LoadingPopup { Message = AppResources.ProgressDialog_UploadingData };
Shell.Current.ShowPopup(loadingPopup);
await _httpClientService.SubmitSupportRequestDataAsync(ticketID, contactType);
var logZipFile = ZipHelper.CreateContactZipFile(_appSettings, _logger, ticketID);
if (!string.IsNullOrWhiteSpace(logZipFile))
await _httpClientService.SubmitSupportRequestLogsAsync(ticketID, logZipFile);
}
finally
{
if (loadingPopup != null)
{
loadingPopup.Close();
loadingPopup.DisposeIfDisposable();
}
}
}
await Browser.OpenAsync(reportUrl, new BrowserLaunchOptions
{
LaunchMode = BrowserLaunchMode.SystemPreferred,
TitleMode = BrowserTitleMode.Show,
PreferredToolbarColor = (Color)Application.Current!.Resources["PrimaryDarkColor"],
PreferredControlColor = (Color)Application.Current!.Resources["DefaultTextColor"]
});
//Crashes here when returning form the browser
Expected Behavior
App not to crash
Steps To Reproduce
See code above
Link to public reproduction project repository
n/a
Environment
- .NET MAUI CommunityToolkit: 11.1.0
- OS: iOS (crashes), Android (works)
- .NET MAUI: 9.0.40Anything else?
No response
Reacted by LambdaLich
Activity
kolodiichyk commentedon Mar 29, 2025
Hey @Sebastian1989101,
Here's why this is problematic:
Mixing async and sync operations: Since Close() is an async void method, it starts an asynchronous operation but doesn't provide a way to await its completion. The code immediately moves on to DisposeIfDisposable(), then exits the finally block and then to Browser.OpenAsync.
The correct approach is to use loadingPopup .CloseAsync() with await