MenuItem Icon exception. #320

Closed
opened 2026-01-29 16:36:24 +00:00 by claunia · 2 comments
Owner

Originally created by @Tum4ik on GitHub (May 20, 2019).

Originally assigned to: @GregorBiswanger on GitHub.

Hi.
I've created a simple tray application. I tried to add icon to some menu item, but it fails.

  public class Desktoper
  {
    private readonly MenuItem[] _menuItems = new[]
    {
      new MenuItem
      {
        Label = "RunStop"
      },
      new MenuItem
      {
        Type = MenuType.separator
      }, 
      new MenuItem
      {
        Label = "Exit",
        Click = ()=> Electron.App.Exit(),
        Icon = "Desktop/icons/tray-stop-icon.png"  // <-- here fails
      }
    };


    public void Desktopize()
    {
      Electron.Tray.Show("Desktop/icons/tray-stop-icon.png", _menuItems);  // <-- here works fine
    }
  }

Here is the exception popup
image

May be it supports only some specific image formats? Help me pls to understand or figure it out.
Thanks!

Originally created by @Tum4ik on GitHub (May 20, 2019). Originally assigned to: @GregorBiswanger on GitHub. Hi. I've created a simple tray application. I tried to add icon to some menu item, but it fails. ```csharp public class Desktoper { private readonly MenuItem[] _menuItems = new[] { new MenuItem { Label = "RunStop" }, new MenuItem { Type = MenuType.separator }, new MenuItem { Label = "Exit", Click = ()=> Electron.App.Exit(), Icon = "Desktop/icons/tray-stop-icon.png" // <-- here fails } }; public void Desktopize() { Electron.Tray.Show("Desktop/icons/tray-stop-icon.png", _menuItems); // <-- here works fine } } ``` Here is the exception popup ![image](https://user-images.githubusercontent.com/21317790/58049013-80ce8c00-7b54-11e9-9bd2-997bd3aa0b58.png) May be it supports only some specific image formats? Help me pls to understand or figure it out. Thanks!
claunia added the question label 2026-01-29 16:36:24 +00:00
Author
Owner

@GregorBiswanger commented on GitHub (May 20, 2019):

This is a native electron problem. You need a complete path to the picture.
https://github.com/electron/electron/issues/7657

Solution for Electron.NET:

new MenuItem
{
    Label = "Exit",
    Click = ()=> Electron.App.Exit(),
    Icon = env.ContentRootPath + "/Desktop/icons/tray-stop-icon.png"
}
@GregorBiswanger commented on GitHub (May 20, 2019): This is a native electron problem. You need a complete path to the picture. https://github.com/electron/electron/issues/7657 **Solution for Electron.NET:** ``` new MenuItem { Label = "Exit", Click = ()=> Electron.App.Exit(), Icon = env.ContentRootPath + "/Desktop/icons/tray-stop-icon.png" } ```
Author
Owner

@Tum4ik commented on GitHub (May 21, 2019):

Nice! Many thanks.

@Tum4ik commented on GitHub (May 21, 2019): Nice! Many thanks.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/Electron.NET#320