BadgeUpdateManager::CreateBadgeUpdaterForApplication() crashes with WinRT originate error - 0x80070490 : 'Element not found.'

Shyam Butani 380 Reputation points
2024-10-04T06:40:08.6566667+00:00

Hello,

I'm trying to show badge icon in the taskbar for my WinUI2 application (WinRT/C++). Below is the code snippet:

    // winrt::init_apartment(apartment_type::single_threaded);

    XmlDocument badgeXml = BadgeUpdateManager::GetTemplateContent(BadgeTemplateType::BadgeNumber);

    auto badgeAttributes = badgeXml.GetElementsByTagName(L"badge");

    if (badgeAttributes.Size() > 0) {

        XmlElement badgeElement = badgeAttributes.GetAt(0).as<XmlElement>();
        badgeElement.SetAttribute(L"value", L"7");
    }

    BadgeNotification badgeNotification = BadgeNotification(badgeXml);

    // Below line crashes
    BadgeUpdater badgeUpdater = BadgeUpdateManager::CreateBadgeUpdaterForApplication();

    badgeUpdater.Update(badgeNotification);

In this code, when the line with BadgeUpdateManager::CreateBadgeUpdaterForApplication() hits, it crashes with the below error:

WinRT originate error - 0x80070490 : 'Element not found.'

Can you please help me to understand the issue here and possible solution for this?

Thanks.

Windows development | Windows API - Win32
{count} vote

Accepted answer
  1. Anonymous
    2024-10-09T02:02:12.3366667+00:00

    Hello,

    Welcome to Microsoft Q&A!

    This is a summary for our discussion.

    After testing, the BadgeUpdateManager and BadgeUpdater only works in UWP and WinUI3 applications. They are not supported in desktop apps like Win32, WPF,etc. If you want to show number badge on taskbar icon in normal desktop apps, please try win32 API ITaskbarList3::SetOverlayIcon.

    Thank you.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

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.