0

I have a trayicon in my WPF App. When I was debugging in Visual Studio, it works well: System.Windows.Forms.NotifyIcon ni = new System.Windows.Forms.NotifyIcon(); ni.Icon = new Icon("../../logo,ico");

But after I published it, the App threw an exception saying it could find the path of the image of the trayicon. I've search a lot resources on online, I saw many solutions use pack, but it seems pack only accept Uri variable and the path for trayicon must be string. I also tried to create a folder called Resource under the project solution and put the image file into it. This was the same: worked while debugging but would not work after publishing..

So based on @WPF Germany's suggestion, I solved the path issue after publishing the App by Clickonce. However, if I copy a App shortcut to system startup folder, it would find the ico in C:\WINDOWS\system32, which is not easy to workaround since systems32 usually requires admin right to access. Any idea for that?

randomcat
  • 413
  • 1
  • 4
  • 16
  • 1
    Why don't you add an Icon to the Resources.resx file of your Visual Studio project and load it by `ni.Icon = Properties.Resources.Logo`? – Clemens Feb 27 '17 at 08:43

1 Answers1

1

Did you check, that your logo.ico file is copied to output path?

In VS you have multiple options to provide your Resource files.

First option:

Select your logo.ico file in solution explorer and choose None as Build Action and Copy always at Copy to Output Directory (at file properties).

After compiling you will find the file in a subdirectory of our OutputPath.

use (if logo.ico is placed in your projects root):

ni.Icon = new Icon("logo.ico");

other option:

Use Resource as Build Action and build your Icon using a Stream created from Resources.logo...

WPFGermany
  • 1,639
  • 2
  • 12
  • 30
  • Thank you it works! But it seems like this only works in c#. If I also need the logo.ico in other xaml files, I need to import the image again with a different name. But anyway it works! – randomcat Feb 27 '17 at 16:38
  • 1
    I had same problem, and I was able to fixed only when I unchecked(set to False) the 'PublishSingleFile'. – Lucian Bumb Nov 02 '20 at 07:37