Skip to content

[BUG] Crash on second window close when SnackBar enabled on Windows (still reproducible in v12.0.0) #2754

Open
@slovan

Description

@slovan

Is there an existing issue for this?

  • I have searched the existing issues

Did you read the "Reporting a bug" section on Contributing file?

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

  1. Create a MAUI app and enable Windows Snackbar in MauiProgram.cs (or use the sample project linked to this ticket).
  2. Launch the app.
  3. Open the secondary window (via the “Click me” button in the sample).
  4. Close that window.
  5. Reopen the secondary window.
  6. 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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions