pr8x / DesktopNotifications

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

Linux Notification Issue #13

Closed Ryoumiya closed 1 year ago

Ryoumiya commented 1 year ago

Error when notification button is pressed on FreeDesktop

Unhandled exception. Tmds.DBus.DisconnectedException: Signal handler for org.freedesktop.Notifications.NotificationClosed threw an exception
 ---> System.InvalidOperationException: Signal handler for org.freedesktop.Notifications.NotificationClosed threw an exception
 ---> System.Collections.Generic.KeyNotFoundException: The given key '16' was not present in the dictionary.
   at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
   at DesktopNotifications.FreeDesktop.FreeDesktopNotificationManager.OnNotificationClosed(ValueTuple`2 event) in /home/ryoumiya/Documents/DesktopNotifications/DesktopNotifications.FreeDesktop/FreeDesktopNotificationManager.cs:line 138
   at Tmds.DBus.WrappedDisposable.Call[T](Action`1 action, T value, Boolean disposes)
   at Tmds.DBus.CodeGen.DBusObjectProxy.<>c__DisplayClass7_0`1.<WatchNonVoidSignalAsync>b__0(Message msg, Exception ex)
   at Tmds.DBus.DBusConnection.HandleSignal(Message msg)
   --- End of inner exception stack trace ---
   at Tmds.DBus.DBusConnection.HandleSignal(Message msg)
   at Tmds.DBus.DBusConnection.HandleMessage(Message msg, IMessageStream peer)
   at Tmds.DBus.DBusConnection.ReceiveMessages(IMessageStream peer, Action`2 disconnectAction)
   --- End of inner exception stack trace ---
   at DesktopNotifications.FreeDesktop.FreeDesktopNotificationManager.OnNotificationActionInvokedError(Exception obj) in /home/ryoumiya/Documents/DesktopNotifications/DesktopNotifications.FreeDesktop/FreeDesktopNotificationManager.cs:line 157
   at Tmds.DBus.WrappedDisposable.Call[T](Action`1 action, T value, Boolean disposes)
   at Tmds.DBus.CodeGen.DBusObjectProxy.<>c__DisplayClass7_0`1.<WatchNonVoidSignalAsync>b__0(Message msg, Exception ex)
   at Tmds.DBus.DBusConnection.Disconnect(Boolean dispose, Exception exception)
   at Tmds.DBus.Connection.Disconnect(Boolean dispose, Exception exception)
   at Tmds.DBus.Connection.OnDisconnect(Exception e)
   at Tmds.DBus.DBusConnection.EmitDisconnected(IMessageStream peer, Exception e)
   at Tmds.DBus.DBusConnection.ReceiveMessages(IMessageStream peer, Action`2 disconnectAction)
   at System.Threading.Tasks.Task.<>c.<ThrowAsync>b__128_1(Object state)
   at System.Threading.ThreadPoolWorkQueue.Dispatch()
   at System.Threading.PortableThreadPool.WorkerThread.WorkerThreadStart()

OS: OpenSuse Leap 15.5 .net: 7.0

Ryoumiya commented 1 year ago

Looks like the error comes from Dictionary in FreeDesktopNotificationManager.cs

private void OnNotificationClosed((uint id, uint reason) @event)
{
    var notification = _activeNotifications[@event.id];  //<-- Here !

    _activeNotifications.Remove(@event.id);

    //TODO: Not sure why but it calls this event twice sometimes
    //In this case the notification has already been removed from the dict.
    if (notification == null)
    {
        return;
    }

    var dismissReason = GetReason(@event.reason);

    NotificationDismissed?.Invoke(this,
        new NotificationDismissedEventArgs(notification, dismissReason));
}

i think i could fix this, let me test a few things first...

onionware-github commented 1 year ago

Same. I also get a crash when I click on the notification itself (not a button) or the close button. Maybe because it tries to get the value from a key without checking if the key exists or the dict get modified by another thread?