Skip to content
This repository was archived by the owner on Feb 25, 2026. It is now read-only.
This repository was archived by the owner on Feb 25, 2026. It is now read-only.

The ToastContentBuilder is unable to set the toast notification sound to a ms-winsoundevent sound #3753

Closed

Description

@EmilJunker

Describe the bug

The ToastContentBuilder in Microsoft.Toolkit.Uwp.Notifications is unable to create a toast notification that uses one of the built-in ms-winsoundevent sounds.

  • Is this bug a regression in the toolkit? If so, what toolkit version did you last see it work: I don't know

Steps to Reproduce

  • Can this be reproduced in the Sample App? (Either in a sample as-is or with new XAML pasted in the editor.) If so, please provide custom XAML or steps to reproduce. If not, let us know why it can't be reproduced (e.g. more complex setup, environment, dependencies, etc...)

Steps to reproduce the behavior:

  1. Add the Microsoft.Toolkit.Uwp.Notifications NuGet package to your UWP app.

  2. Then put this code in your UWP app:

ToastContent toast = new ToastContentBuilder()
    .AddText("Hello World")
    .AddAudio(new Uri("ms-winsoundevent:Notification.Mail"))
    GetToastContent();
  1. Run the app.

Expected behavior

The ToastContentBuilder should create a ToastContent object equivalent to the following XML content:

<toast>
    <visual>
        <binding template='ToastGeneric'>
            <text>Hello World</text>
        </binding>
    </visual>
    <audio src='ms-winsoundevent:Notification.Mail'/>
</toast>

Actual behavior

The following exception is thrown:

System.ArgumentException
  HResult=0x80070057
  Message=src
Parameter name: Audio Source has to be a file.
  Source=Microsoft.Toolkit.Uwp.Notifications
  StackTrace:
   at Microsoft.Toolkit.Uwp.Notifications.ToastContentBuilder.AddAudio(Uri src)
   at LessonTimer.Services.Notifications.ScheduleToastNotification(String source, DateTime time) in ..\Notifications.cs:line 39
   at LessonTimer.MainPage.ScheduleNotification() in ..\MainPage.xaml.cs:line 286
   at LessonTimer.MainPage.StartCountdown() in ..\MainPage.xaml.cs:line 259
   at LessonTimer.MainPage.StartButton_Click(Object sender, RoutedEventArgs e) in ..\MainPage.xaml.cs:line 177

Screenshots

If applicable, add screenshots to help explain your problem.

Environment

NuGet Package(s):
- Microsoft.NETCore.UniversalWindowsPlatform (v6.2.12),
- Microsoft.Services.Store.Engagement (v10.1901.28001),
- Microsoft.Toolkit.Uwp.Notifications (v6.1.1)

Windows 10 Build Number:
- [ ] Fall Creators Update (16299)
- [ ] April 2018 Update (17134)
- [ ] October 2018 Update (17763)
- [ ] May 2019 Update (18362)
- [ ] May 2020 Update (19041)
- [x] Insider Build (build number: 19042.804)

App min and target version:
- [x] Fall Creators Update (16299)
- [ ] April 2018 Update (17134)
- [ ] October 2018 Update (17763)
- [ ] May 2019 Update (18362)
- [x] May 2020 Update (19041)
- [ ] Insider Build (xxxxx)

Device form factor:
- [x] Desktop
- [ ] Xbox
- [ ] Surface Hub
- [ ] IoT

Visual Studio 
- [ ] 2017 (version: )
- [x] 2019 (version: 16.8.5) 
- [ ] 2019 Preview (version: )

Additional context

Add any other context about the problem here.

Activity

  1. added
    bug 🐛An unexpected issue that highlights incorrect behavior
    on Feb 12, 2021
  2. Kyaa-dost commented on Feb 12, 2021

    @Kyaa-dost
    Contributor

    Thanks, @EmilJunker for the detailed description. Tagging this for further investigation. Let's see if any community member can help identify the root cause.

  3. michael-hawker commented on Feb 12, 2021

    @michael-hawker
    Member
  4. andrewleader commented on Feb 12, 2021

    @andrewleader
    Contributor

    Hey @EmilJunker thanks for reporting this. As a quick workaround, you can update to the 7.0.0-preview4 prerelease version of the NuGet package and use the following method that accepts a ToastAudio object... I tested the below and it works. Looks like in our other method we were checking to make sure it was a file, but this new alternative method doesn't require it to be a file.

    new ToastContentBuilder()
        .AddText("Check out this sound!")
        .AddAudio(new ToastAudio()
        {
            Src = new Uri("ms-winsoundevent:Notification.Looping.Alarm2")
        })
        .Show();

    You can also use the new simplified Show() API as seen above with the new preview. Docs here: https://aka.ms/toast7

    I'll get the bug itself fixed for the other AddAudio method! Thanks again for reporting this!

  5. added this to the 7.0 milestone on Feb 16, 2021
  6. ghost removed
    help wantedIssues identified as good community contribution opportunities
    on Feb 16, 2021
  7. ghost closed this as completedin #3755on Feb 16, 2021
  8. ghost added a commit that references this issue on Feb 16, 2021
    4e54ec5
  9. ghost locked as resolved and limited conversation to collaborators on Apr 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions