Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
2 of 24 tasks
McSaverInvestments opened this issue Oct 7, 2024 · 5 comments · May be fixed by #2259
Labels
area/alerts Issue/Discussion/PR that has to do with Alerts bug Something isn't working unverified

Comments

@McSaverInvestments
Copy link

McSaverInvestments commented Oct 7, 2024

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.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.b__22_4(Window _, WindowEventArgs _)
at Microsoft.Maui.MauiWinUIWindow.<>c__DisplayClass10_0.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)
  • 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)
  • 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

Preview Give feedback
No tasks being tracked yet.
@michael-hawker michael-hawker transferred this issue from CommunityToolkit/Windows Oct 14, 2024
Copy link
Contributor

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.

@brminnick brminnick added bug Something isn't working unverified labels Oct 14, 2024
@McSaverInvestments
Copy link
Author

McSaverInvestments commented Oct 14, 2024 via email

@brminnick
Copy link
Collaborator

brminnick commented Oct 14, 2024

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

@McSaverInvestments
Copy link
Author

McSaverInvestments commented Oct 17, 2024

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

@ne0rrmatrix ne0rrmatrix linked a pull request Oct 17, 2024 that will close this issue
6 tasks
@vhugogarcia vhugogarcia added the area/alerts Issue/Discussion/PR that has to do with Alerts label Oct 23, 2024
@McSaverInvestments
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/alerts Issue/Discussion/PR that has to do with Alerts bug Something isn't working unverified
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants