pr8x / DesktopNotifications

A cross-platform C# library for native desktop "toast" notifications.
MIT License
182 stars 32 forks source link

Version 1.3.0 fails with System.PlatformNotSupportedException on Windows #22

Closed nefarius closed 1 year ago

nefarius commented 1 year ago

Hey hey,

so I updated from 1.2.0 to 1.3.0 today and the same unchanged code now fails with

System.PlatformNotSupportedException 
Operation is not supported on this platform.
   at DesktopNotifications.Windows.WindowsNotificationManager..ctor(WindowsApplicationContext context)

My code:

public partial class App : Application
{
    private readonly IHost _host;

    public App()
    {
        _host = Host.CreateDefaultBuilder()
            .ConfigureServices((hostContext, services) =>
            {
                services.AddSingleton<INotificationManager, WindowsNotificationManager>();

                services.AddHostedService<UpdateMessageSubscriber>();
            }).Build();
    }

    private async void App_OnStartup(object sender, StartupEventArgs e)
    {
        // throws exception now
        INotificationManager notificationManager = _host.Services.GetRequiredService<INotificationManager>();

        await notificationManager.Initialize();

        await _host.StartAsync();
    }
}

Thank you!

pr8x commented 1 year ago

Which platform are you running on?

pr8x commented 1 year ago

Oh I know why this is happening. I am creating nugets on the CI, but only under ubuntu environment. So the windows package will be broken since it uses the "null impl". Will fix.

nefarius commented 1 year ago

Which platform are you running on?

To answer your question, happens on both Windows 10 and 11.

pr8x commented 1 year ago

@nefarius I rebuilt the packages locally and pushed v1.3.1 to nuget. Make sure to target either net6.0-windows10.0.17763.0 or n etcoreapp3.1 in your application. It doesn't wotk with net6.0 unfortunately due to the windows-specific TFM used internally. I will add a note about that in the readme.

pr8x commented 1 year ago

Now it seems to work on Windows (using 1.3.1) but fails to compile on Linux again (with net6.0 target). Honestly multi-target and multi-OS stuff with .NET is pure horror.

nefarius commented 1 year ago

The error is gone now, thank you! Now I need to figure out why I am not getting any notifications whatsoever on Windows 11, but I haven't yet pinned down that issue to something with the library or not.

pr8x commented 1 year ago

Are you seeing the application in the windows Start menu?

nefarius commented 1 year ago

Are you seeing the application in the windows Start menu?

Good point, I'll get back to you on this tomorrow.

nefarius commented 1 year ago

Are you seeing the application in the windows Start menu?

Yep, it's there!

nefarius commented 1 year ago

Did a few more tests, nothing is appearing on Windows 11 22H2, no exceptions, nothing in Event Viewer... 🤔

nefarius commented 1 year ago

NVM just tried it in a fresh Windows 11 VM and there it works as expected, must be something wrong with the particular test machine, closing, thanks!