Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NotifyIcon Windows 10 works on Debug but not on Publish

I stumble upon a weird bug on my desktop application, written in c#, NET 4.5, using Windows Form. I've implemented a simple NotifyIcon system that listen a specific list and, for every item added, it display the title and the description. Pretty straight forward.

It works like a charm during the Debug process, but when I publish the application no notification is shown for whatever reason. Am I missing some particular permission on Windows10?

This is the code of the EventHandler

    /// <summary>
    /// 
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="args"></param>
    private void OnLogItemAdded(object sender, Utilities.ItemAddedEventArgs args)
    {
        Event e = (Event)args.item;
        switch (e.eventType)
        {
            case EventType.Info:
                MainNotifyIcon.BalloonTipIcon = ToolTipIcon.Info;
                break;
            case EventType.Error:
                MainNotifyIcon.BalloonTipIcon = ToolTipIcon.Error;
                break;
            case EventType.Warning:
                MainNotifyIcon.BalloonTipIcon = ToolTipIcon.Warning;
                break;
            default:
                MainNotifyIcon.BalloonTipIcon = ToolTipIcon.Info;
                break;
        }
        MainNotifyIcon.Visible = true;
        MainNotifyIcon.BalloonTipTitle = e.Title;
        MainNotifyIcon.BalloonTipText = e.Description;
        MainNotifyIcon.ShowBalloonTip(3000);
    }

That's it, no other code is involved.

Based on the comment the notification icon should be explicitly set. I did it but still no results. Icon is a resource icon included in the project

MainNotifyIcon.Icon = Properties.Resources.icon;
like image 573
Ludo237 Avatar asked Oct 19 '22 02:10

Ludo237


2 Answers

I ran into the same issue that didn't work in Debug mode either.

If you don't compile your code with "Any CPU" or "x64" and deploy on a Windows 10 64 bits in %ProgramFiles% (not %ProgramFiles(x86)% !) toast notifications will never appear.

However it works in non-64 bits specific folder.

like image 153
Tigzy Avatar answered Oct 21 '22 17:10

Tigzy


The launch icon created by the .NET publisher creates some kind of shortcut (called an Application Reference) in C:\Users\USERNAME\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\PUBLISHER\YOUR APP

The notifications don't work when you launch the application using this reference. Not sure why (bug?) but the issue is gone when you launch it using the .exe, you can probably find it somewhere here: C:\Users\USERNAME\AppData\Local\Apps\2.0\ID\ID\ID\YOUR APP.exe

like image 25
Sander88 Avatar answered Oct 21 '22 17:10

Sander88