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
A .NET MAUI app using multiple windows and enabling snackbar notifications for Windows via:
builder.UseMauiApp<App>().UseMauiCommunityToolkit(options => options.SetShouldEnableSnackbarOnWindows(true));
On the second window close (i.e., after opening, closing, reopening, and then closing the secondary window), the app crashes with an unhandled exception:
Element not found.
Not Registered for App Notifications!
and this stack trace:
at WinRT.ExceptionHelpers.g__Throw|38_0(Int32 hr)
at ABI.Microsoft.Windows.AppNotifications.IAppNotificationManagerMethods.Unregister(IObjectReference _obj)
at Microsoft.Windows.AppNotifications.AppNotificationManager.Unregister()
at CommunityToolkit.Maui.Options.<>c.b__22_4(Window _, WindowEventArgs ) in //src/CommunityToolkit.Maui/Options.cs:line 93
at Microsoft.Maui.MauiWinUIWindow.<>c__DisplayClass10_0.b__0(OnClosed del)
at Microsoft.Maui.LifecycleEvents.LifecycleEventServiceExtensions.InvokeLifecycleEvents[TDelegate](IServiceProvider services, Action`1 action)
at Microsoft.Maui.MauiWinUIWindow.OnClosed(Object sender, WindowEventArgs args)
at Microsoft.Maui.MauiWinUIWindow.OnClosedPrivate(Object sender, WindowEventArgs args)
at WinRT.EventSource_global__Windows_Foundation_TypedEventHandler_object__global__Microsoft_UI_Xaml_WindowEventArgs.EventState.b__1_0(Object sender, WindowEventArgs args)
at WinRT.GenericTypeInstantiations.Windows_Foundation_TypedEventHandler_2_object__Microsoft_UI_Xaml_WindowEventArgs.Do_Abi_Invoke(IntPtr thisPtr, IntPtr sender, IntPtr args)
Expected Behavior
The second window should open and close repeatedly without throwing an exception.
Steps To Reproduce
- Create a MAUI app and enable Windows Snackbar in MauiProgram.cs (or use the sample project linked to this ticket).
- Launch the app.
- Open the secondary window (via the “Click me” button in the sample).
- Close that window.
- Reopen the secondary window.
- Close it again - and observe the crash on the second close.
Link to public reproduction project repository
https://github.com/slovan/MultiWindowIssueRepro
Environment
- .NET MAUI CommunityToolkit: 12.0.0
- OS: Windows 11 Build 10.0.26100
- .NET MAUI: 9.0.301
Anything else?
- The exception occurs only on the second window close, not the first.
- The original issue Application crashes upon closing a second window when using Builder.options.SetShouldEnableSnackbarOnWindows(true) #2279 was closed automatically when PR Fix Windows Media Element in MultiWindow Mode on exit Crash #2259 was merged. However, the crash still occurs in 12.0.0.
- I have reproduced the issue with the following CommunityToolkit.Maui versions in addition to the mentioned above: 11.0.0, 11.1.0, 11.1.1 and 11.2.0.
- The last known working version where this did not occur is 10.0.0.