Share via

Toast notifies that an exception has occurred

Starcloudsea 60 Reputation points
Oct 5, 2023, 10:04 AM

As shown in the picture: my Toast notifications throw this exception: System.Runtime.InteropServices.COMException: "Unspecified error", I copied and pasted

https://learn.microsoft.com /zh-cn/windows/apps/windows-app-sdk/migrate-to-windows-app-sdk/guides/toast-notifications,

why is this? How can I fix it?

Thanks!

User's image

.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,988 questions
Windows App SDK
Windows App SDK
A set of Microsoft open-source libraries, frameworks, components, and tools to be used in apps to access Windows platform functionality on many versions of Windows. Previously known as Project Reunion.
801 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,124 questions
Windows 11
Windows 11
A Microsoft operating system designed for productivity, creativity, and ease of use.
10,188 questions
{count} votes

Accepted answer
  1. Castorix31 86,316 Reputation points
    Oct 6, 2023, 7:30 AM

    This test from MSDN samples works for me with WinUI 3 and Microsoft.Toolkit.Uwp.Notifications

    (I had to change the logo to an existing file) :

    {
        ToastNotificationManagerCompat.OnActivated += ToastNotificationManagerCompat_OnActivated;
        var toastContent = new ToastContent()
        {
            Visual = new ToastVisual()
            {
                BindingGeneric = new ToastBindingGeneric()
                {
                    Children =
                    {
                        new AdaptiveText()
                        {
                            Text = "Matt sent you a friend request"
                        },
                        new AdaptiveText()
                        {
                            Text = "Hey, wanna dress up as wizards and ride around on our hoverboards together?"
                        }
                    },
                    AppLogoOverride = new ToastGenericAppLogo()
                    {
                        //Source = "https://unsplash.it/64?image=1005",
                        //Source = "https://fastly.picsum.photos/id/1005/64/64.jpg?hmac=GfOyTHJcxsTTn0EXugyviiROYAqGAdDtqvf3zLOzwfA",
                        //Source = "ms-appx:///Assets/Butterfly.png",
                        Source = "E:\\Butterfly.png",
                        HintCrop = ToastGenericAppLogoCrop.Default
                    }
                }
            },
            Actions = new ToastActionsCustom()
            {
                Buttons =
                {
                    new ToastButton("Accept", "action=acceptFriendRequest&userId=49183")
                    {
                        ActivationType = ToastActivationType.Background
                    },
                    new ToastButton("Decline", "action=declineFriendRequest&userId=49183")
                    {
                        ActivationType = ToastActivationType.Background
                    }
                }
            },
            Launch = "action=viewFriendRequest&userId=49183"
        };
    
        // Create the toast notification
        var toastNotif = new ToastNotification(toastContent.GetXml());
        toastNotif.Activated += ToastNotif_Activated;
        toastNotif.Failed += ToastNotif_Failed;
        toastNotif.Dismissed += ToastNotif_Dismissed;
        // And send the notification
        ToastNotificationManagerCompat.CreateToastNotifier().Show(toastNotif);
    }
    
          private void ToastNotif_Dismissed(ToastNotification sender, ToastDismissedEventArgs args)
          {
              Console.Beep(2000, 10);
          }
    
          private void ToastNotif_Failed(ToastNotification sender, ToastFailedEventArgs args)
          {
              int i = 1;
              // WPN_E_NOTIFICATION_TYPE_DISABLED
              //            HResult = -2143420140
              //ErrorCode = { "Les paramètres empêchent la remise de ce type de notification. (0x803E0114)"}
          }
    
          private void ToastNotif_Activated(ToastNotification sender, object args)
          {
              Console.Beep(5000, 10);
          }
    
          private void ToastNotificationManagerCompat_OnActivated(ToastNotificationActivatedEventArgsCompat e)
          {
              // Obtain the arguments from the notification
              ToastArguments toastArgs = ToastArguments.Parse(e.Argument);
             // Code...
          }
    
    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.