Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Toast notification Collections crash when initializing.

Toast notification Collections crash when initializing.

Scheduled Pinned Locked Moved C#
wpfcomdesignlinuxdevops
11 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Maximilien

    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.cs

    Any 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

    L Offline
    L Offline
    Lost User
    wrote on last edited by
    #2

    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

    M 1 Reply Last reply
    0
    • M Maximilien

      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.cs

      Any 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

      Richard DeemingR Offline
      Richard DeemingR Offline
      Richard Deeming
      wrote on last edited by
      #3

      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

      "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

      M 1 Reply Last reply
      0
      • L Lost User

        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

        M Offline
        M Offline
        Maximilien
        wrote on last edited by
        #4

        Even if I run non-async, I still crash at the line :

        ToastCollectionManager collectionManager = defaultManager.GetToastCollectionManager();

        CI/CD = Continuous Impediment/Continuous Despair

        L 1 Reply Last reply
        0
        • Richard DeemingR Richard Deeming

          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

          M Offline
          M Offline
          Maximilien
          wrote on last edited by
          #5

          see other answer above, I still crash.

          CI/CD = Continuous Impediment/Continuous Despair

          1 Reply Last reply
          0
          • M Maximilien

            Even if I run non-async, I still crash at the line :

            ToastCollectionManager collectionManager = defaultManager.GetToastCollectionManager();

            CI/CD = Continuous Impediment/Continuous Despair

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #6

            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

            M 1 Reply Last reply
            0
            • L Lost User

              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

              M Offline
              M Offline
              Maximilien
              wrote on last edited by
              #7

              no, from a button on my form.

              CI/CD = Continuous Impediment/Continuous Despair

              L 1 Reply Last reply
              0
              • M Maximilien

                no, from a button on my form.

                CI/CD = Continuous Impediment/Continuous Despair

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #8

                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

                M 1 Reply Last reply
                0
                • L Lost User

                  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

                  M Offline
                  M Offline
                  Maximilien
                  wrote on last edited by
                  #9

                  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

                  S 1 Reply Last reply
                  0
                  • M Maximilien

                    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

                    S Offline
                    S Offline
                    Sayyid Sadik
                    wrote on last edited by
                    #10

                    Any solution for this?

                    M 1 Reply Last reply
                    0
                    • S Sayyid Sadik

                      Any solution for this?

                      M Offline
                      M Offline
                      Maximilien
                      wrote on last edited by
                      #11

                      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

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups