Maui icon indicating copy to clipboard operation
Maui copied to clipboard

Application crashes upon closing a second window when using Builder.options.SetShouldEnableSnackbarOnWindows(true)

Open McSaverInvestments opened this issue 1 year ago • 4 comments

Describe the bug

I am trying to use SnackBar in my application. My application supports multiple windows.
There appears to be an issue upon closing a second windows.

Here is a link to the repo: https://github.com/McSaverInvestments/TestToolKit2

Steps to reproduce

*******    Steps to set up Test MAUI Application which demostrates the bug   ***********************
1)   Inside of visual studio(Version 17.12.0 Preview 2.1) create a new .Net Maui App called TestToolKit2
        Note: The Preview version of visual studio is irrelevant
		Using .NET 8 long term support
2)   Add a Dependency for the CommunityToolkit.MAUI to the new project
3)   To support SnackBar, Modify the Package.appxmaniest file in the Platforms.Windows folder 
		a)  Change Line 7 to the following 
				IgnorableNamespaces="uap rescap com desktop">
		  
        b)  Add the following after (Line 6 and before Line 7)
			   xmlns:com="http://schemas.microsoft.com/appx/manifest/com/windows10"
			   xmlns:desktop="http://schemas.microsoft.com/appx/manifest/desktop/windows10"
		  

        c)  Add the following after Line 40 (</uap:VisualElements>)
		      <Extensions>
				<!-- Specify which CLSID to activate when notification is clicked -->
				<desktop:Extension Category="windows.toastNotificationActivation">
				  <desktop:ToastNotificationActivation ToastActivatorCLSID="6e919706-2634-4d97-a93c-2213b2acc334" />
				</desktop:Extension>

				<!-- Register COM CLSID -->
				<com:Extension Category="windows.comServer">
				  <com:ComServer>
					<com:ExeServer Executable="TestToolKit2\TestToolKit2.exe" DisplayName="$targetnametoken$" Arguments="----AppNotificationActivated:">
					  <com:Class Id="6e919706-2634-4d97-a93c-2213b2acc334" />
					</com:ExeServer>
				  </com:ComServer>
				</com:Extension>
			  </Extensions>
4)   Add the following to MauiProgram.cs after the builder's .UseMauiApp<App>() line of code (Line 12)
                    .UseMauiCommunityToolkit(options =>
                    {
                        // BUG:   Application crashes when a true is passed
                        options.SetShouldEnableSnackbarOnWindows(true);
                    })
					
		NOTE:  don't forget to add the following to the top of MauiProgram.cs
					using CommunityToolkit.Maui;
4)   Add the following button to MainPage.xaml (on Line 33)
            <Button
               x:Name="OpenWndBtn"
               Text="Open Window" 
               SemanticProperties.Hint="Open a window when you click"
               Clicked="OnOpenWndClicked"
               HorizontalOptions="Fill" />
5)   Add the following code to MainPage.xaml.cs (after Line 11)
			private void OnOpenWndClicked(object sender, EventArgs e)
			{
				TestWindow.OpenNewWindow(new TestWindow());
			}
6)   Add a new item (TestWindow.cs) to the project and replace the code with the following
		namespace TestToolKit2
		{
			internal class TestWindow : Window
			{
				#region Static -  Methods
				public static void OpenNewWindow<TWindow>(TWindow aWindow)
					 where TWindow : Window
				{
					Application.Current!.OpenWindow(aWindow);
				} 
				#endregion

				public TestWindow()
				{
					Page = new TestPage();
				}
			}
		}
7)   Add a new .NET MAUI ContentPage (XAML) called TestPage.xaml to the project
        NOTE: the default generated code supplied by Visual Studio is fine.



//    ******   Steps to produce the error   *********************
//
//   Note:   Using true in the follow line of CreateMauiApp() causes the error to occurs
//               options.SetShouldEnableSnackbarOnWindows(true);
//
// Steps:
//      1)   Start application (Platform:  Windows Machine)
//      2)   Click button that open an additional Window
//      3)   Close that new window
//      4)   Click button that open an second addition Window
//      5)   Close that new window   ( Error seen below occurs on closing second window )

Expected behavior

Windows should close without abort the application!

Here is the call stack: at WinRT.ExceptionHelpers.<ThrowExceptionForHR>g__Throw|39_0(Int32 hr) at ABI.Microsoft.Windows.AppNotifications.IAppNotificationManagerMethods.Unregister(IObjectReference _obj) at Microsoft.Windows.AppNotifications.AppNotificationManager.Unregister() at CommunityToolkit.Maui.Options.<>c.<SetShouldEnableSnackbarOnWindows>b__22_4(Window _, WindowEventArgs _) at Microsoft.Maui.MauiWinUIWindow.<>c__DisplayClass10_0.<OnClosed>b__0(OnClosed del) at Microsoft.Maui.LifecycleEvents.LifecycleEventServiceExtensions.InvokeLifecycleEvents[TDelegate](IServiceProvider services, Action1 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.<GetEventInvoke>b__1_0(Object sender, WindowEventArgs args) at ABI.Windows.Foundation.TypedEventHandler2.Do_Abi_Invoke[TSenderAbi,TResultAbi](Void* thisPtr, TSenderAbi sender, TResultAbi args)

Screenshots

No response

Code Platform

  • [ ] UWP
  • [ ] WinAppSDK / WinUI 3
  • [ ] Web Assembly (WASM)
  • [ ] Android
  • [ ] iOS
  • [ ] MacOS
  • [ ] Linux / GTK

Windows Build Number

  • [ ] Windows 10 1809 (Build 17763)
  • [ ] Windows 10 1903 (Build 18362)
  • [ ] Windows 10 1909 (Build 18363)
  • [ ] Windows 10 2004 (Build 19041)
  • [ ] Windows 10 20H2 (Build 19042)
  • [ ] Windows 10 21H1 (Build 19043)
  • [ ] Windows 10 21H2 (Build 19044)
  • [ ] Windows 10 22H2 (Build 19045)
  • [ ] Windows 11 21H2 (Build 22000)
  • [X] Other (specify)

Other Windows Build number

Windows 11 10.0.26100 (Build 26100)

App minimum and target SDK version

  • [ ] Windows 10, version 1809 (Build 17763)
  • [ ] Windows 10, version 1903 (Build 18362)
  • [ ] Windows 10, version 1909 (Build 18363)
  • [ ] Windows 10, version 2004 (Build 19041)
  • [ ] Windows 10, version 2104 (Build 20348)
  • [ ] Windows 11, version 22H2 (Build 22000)
  • [X] Other (specify)

Other SDK version

10.0.19041.0

Visual Studio Version

2022, Preview

Visual Studio Build Number

Microsoft Visual Studio Community 2022 (ARM 64-bit) - Version 17.12.0 Preview 2.1

Device form factor

Desktop

Additional context

No response

Help us help you

Yes, I'd like to be assigned to work on this item.

### Tasks

McSaverInvestments avatar Oct 07 '24 22:10 McSaverInvestments

Hi @McSaverInvestments. We have added the "needs reproduction" label to this issue, which indicates that we cannot take further action. This issue will be closed automatically in 5 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

Hello Maui Toolkit,

I gave a very detail work flow so you can be able to reproduce the error, please let me know if you need anything more or if you need a link to a repo to see the error in action.

Thanks McSaverInvestments

On Monday, October 14, 2024, dotnet-policy-service[bot] < @.***> wrote:

Hi @McSaverInvestments https://github.com/McSaverInvestments. We have added the "needs reproduction" label to this issue, which indicates that we cannot take further action. This issue will be closed automatically in 5 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

— Reply to this email directly, view it on GitHub https://github.com/CommunityToolkit/Maui/issues/2279#issuecomment-2411820155, or unsubscribe https://github.com/notifications/unsubscribe-auth/AY66BRDAY5JW67KYI26K44LZ3P3WPAVCNFSM6AAAAABP5MRH4GVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDIMJRHAZDAMJVGU . You are receiving this because you were mentioned.Message ID: @.***>

McSaverInvestments avatar Oct 14 '24 22:10 McSaverInvestments

please let me know if you need anything more or if you need a link to a repo to see the error in action

Yes, thank you. Please edit your Description of the bug and add a link to an open source repository containing a reproduction sample.

Here is more information from ourContributing.md:

Contributing.md

https://github.com/CommunityToolkit/Maui/blob/main/CONTRIBUTING.md#reporting-a-bug

Image

TheCodeTraveler avatar Oct 14 '24 22:10 TheCodeTraveler

I have edited my original post and added the a link to the repo, here in this message too.

https://github.com/McSaverInvestments/TestToolKit2

Thanks.

@brminnick

McSaverInvestments avatar Oct 17 '24 00:10 McSaverInvestments

Verified the fixed for [Fix Windows Media Element in MultiWindow Mode on exit Crash #2259 does in fact fix this issue.

McSaverInvestments avatar Oct 26 '24 13:10 McSaverInvestments