Search code examples
c#visual-studio-codecompiler-errorsconsoledotnet-cli

ToastContentBuilder' does not contain a definition for 'Show'


I am newbie c# , my first try on Visual Studio Code is to show notification on windows 10 using ToastContentBuilder from Namespace Microsoft.Toolkit.Uwp.Notifications here is my code :

using Microsoft.Toolkit.Uwp.Notifications;

namespace cs
{
class Program
{
    static void Main(string[] args)
    {
     
        new ToastContentBuilder ()
        .AddArgument("action","hello")
        .AddText("my first try in csharp)")
        .Show();
       
    }
}

}

and this is the error :'ToastContentBuilder' does not contain a definition for 'Show' and no accessible extension method 'Show' accepting a first argument of type 'ToastContentBuilder' could be found (are you missing a using directive or an assembly reference?)


Solution

  • Show() is only available with the #if WINDOWS_UWP conditional compilation symbol. See the source:

    https://github.com/windows-toolkit/WindowsCommunityToolkit/blob/master/Microsoft.Toolkit.Uwp.Notifications/Toasts/Builder/ToastContentBuilder.cs

    Try using a UWP project template instead of console app.