Toast notification Collections crash when initializing.
-
I'm trying to setup a a ToastNotification collection for our toast notifications (which are working, we can create the notifications.) I'm following this example : [Toast Collections - Windows apps | Microsoft Docs](https://docs.microsoft.com/en-us/windows/apps/design/shell/tiles-and-notifications/toast-collections) The collection is needed to set a custom name to the notification collections; it usually takes the assembly name. (which can be done but it's a hack) The method is called after creating the main window. The defaultManager has a member "User=null"; I'm not sure if it is a valid value for a Default Manager ? It crashes when getting the GetToastCollectionManager :
System.Exception
HResult=0x80070490
Message=Element not found. (0x80070490)
Source=
StackTrace:This exception was originally thrown at this call stack:
WpfApp1.MainWindow.CreateToastCollection() in MainWindow.xaml.cs
WpfApp1.MainWindow.MainWindow() in MainWindow.xaml.csAny ideas ?
private async void SetNotificationCollections() { string displayName = "Is Potato"; string launchArg = "NavigateToPotato"; System.Uri iconURI = new System.Uri("ms-appx:///Assets/icon.png"); ToastCollection licensingManagerToastCollection = new ToastCollection( "MyToastCollection", displayName, launchArg, iconURI); ToastNotificationManagerForUser defaultManager = ToastNotificationManager.GetDefault(); try { ToastCollectionManager collectionManager = defaultManager.GetToastCollectionManager(); //CRASH/exception here. await collectionManager.SaveToastCollectionAsync(licensingManagerToastCollection); } catch { return; } }
CI/CD = Continuous Impediment/Continuous Despair
I don't think calling async methods from a constructor, particularly the main one, is a good idea; like skipping while running. Try the "Loaded" event instead ("window ready for interaction"). Or try a button event (initially) so you have more control overall.
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
-
I'm trying to setup a a ToastNotification collection for our toast notifications (which are working, we can create the notifications.) I'm following this example : [Toast Collections - Windows apps | Microsoft Docs](https://docs.microsoft.com/en-us/windows/apps/design/shell/tiles-and-notifications/toast-collections) The collection is needed to set a custom name to the notification collections; it usually takes the assembly name. (which can be done but it's a hack) The method is called after creating the main window. The defaultManager has a member "User=null"; I'm not sure if it is a valid value for a Default Manager ? It crashes when getting the GetToastCollectionManager :
System.Exception
HResult=0x80070490
Message=Element not found. (0x80070490)
Source=
StackTrace:This exception was originally thrown at this call stack:
WpfApp1.MainWindow.CreateToastCollection() in MainWindow.xaml.cs
WpfApp1.MainWindow.MainWindow() in MainWindow.xaml.csAny ideas ?
private async void SetNotificationCollections() { string displayName = "Is Potato"; string launchArg = "NavigateToPotato"; System.Uri iconURI = new System.Uri("ms-appx:///Assets/icon.png"); ToastCollection licensingManagerToastCollection = new ToastCollection( "MyToastCollection", displayName, launchArg, iconURI); ToastNotificationManagerForUser defaultManager = ToastNotificationManager.GetDefault(); try { ToastCollectionManager collectionManager = defaultManager.GetToastCollectionManager(); //CRASH/exception here. await collectionManager.SaveToastCollectionAsync(licensingManagerToastCollection); } catch { return; } }
CI/CD = Continuous Impediment/Continuous Despair
Avoid async void methods | You’ve Been Haacked[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
I don't think calling async methods from a constructor, particularly the main one, is a good idea; like skipping while running. Try the "Loaded" event instead ("window ready for interaction"). Or try a button event (initially) so you have more control overall.
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
Even if I run non-async, I still crash at the line :
ToastCollectionManager collectionManager = defaultManager.GetToastCollectionManager();
CI/CD = Continuous Impediment/Continuous Despair
-
Avoid async void methods | You’ve Been Haacked[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
see other answer above, I still crash.
CI/CD = Continuous Impediment/Continuous Despair
-
Even if I run non-async, I still crash at the line :
ToastCollectionManager collectionManager = defaultManager.GetToastCollectionManager();
CI/CD = Continuous Impediment/Continuous Despair
And you're still calling it from the constructor?
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
-
And you're still calling it from the constructor?
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
no, from a button on my form.
CI/CD = Continuous Impediment/Continuous Despair
-
no, from a button on my form.
CI/CD = Continuous Impediment/Continuous Despair
Here's the constructor you're calling:
public ToastCollection( string collectionId, string displayName, string launchArgs, Uri iconUri ) {
ApiInformation.TryRaiseNotImplemented(
"Windows.UI.Notifications.ToastCollection",
"ToastCollection.ToastCollection(string collectionId, string displayName, string launchArgs, Uri iconUri)" );
}Seems perhaps you need to provide your own implementation of said collection.
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
-
Here's the constructor you're calling:
public ToastCollection( string collectionId, string displayName, string launchArgs, Uri iconUri ) {
ApiInformation.TryRaiseNotImplemented(
"Windows.UI.Notifications.ToastCollection",
"ToastCollection.ToastCollection(string collectionId, string displayName, string launchArgs, Uri iconUri)" );
}Seems perhaps you need to provide your own implementation of said collection.
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
As stated, AFAIK, the crash/exception is not in the collection constructor, it's when calling :
ToastNotificationManagerForUser defaultManager = ToastNotificationManager.GetDefault(); ToastCollectionManager collectionManager = defaultManager.GetToastCollectionManager(); // crash here
CI/CD = Continuous Impediment/Continuous Despair
-
As stated, AFAIK, the crash/exception is not in the collection constructor, it's when calling :
ToastNotificationManagerForUser defaultManager = ToastNotificationManager.GetDefault(); ToastCollectionManager collectionManager = defaultManager.GetToastCollectionManager(); // crash here
CI/CD = Continuous Impediment/Continuous Despair
Any solution for this?
-
Any solution for this?
Nope, we decided that it was not worth the effort to make it work. Maybe we'll look at it in the future.
CI/CD = Continuous Impediment/Continuous Despair