Can't use MenuRole.undo in custom application menu #451

Closed
opened 2026-01-29 16:39:56 +00:00 by claunia · 1 comment
Owner

Originally created by @jjuback on GitHub (Feb 7, 2020).

Originally assigned to: @GregorBiswanger on GitHub.

  • Version: 7.30.2
  • .NET Core: 3.1
  • Node.js: 10.15.3
  • Target: macOS

When using Electron.Menu.SetApplicationMenu to replace the default Electron menu, you cannot include a menu item with the undo menu role. Doing so results in the following error:

Uncaught Exception:
TypeError: Invalid template for MenuItem: must have at least one of label, role or type
    at Function../lib/browser/api/menu.js.Menu.buildFromTemplate (electron/js2c/browser_init.js:1918:11)

Steps to Reproduce:

  1. In Startup.cs, create a menu template like this:
    MenuItem[] menu = new MenuItem[]
    {
        new MenuItem { Label = "File", Submenu = new MenuItem[]
        {
            new MenuItem { Role = MenuRole.close }
        }},

        new MenuItem { Label = "Edit", Submenu = new MenuItem[]
        {
            new MenuItem { Role = MenuRole.undo },
            new MenuItem { Role = MenuRole.redo },
            new MenuItem { Type = MenuType.separator },
            new MenuItem { Role = MenuRole.cut },
            new MenuItem { Role = MenuRole.copy },
            new MenuItem { Role = MenuRole.paste }
        }}
    };
  1. Before calling CreateWindowAsync, attempt to use the template as the application menu:
Electron.Menu.SetApplicationMenu(menu);
Originally created by @jjuback on GitHub (Feb 7, 2020). Originally assigned to: @GregorBiswanger on GitHub. * **Version**: 7.30.2 * **.NET Core**: 3.1 * **Node.js**: 10.15.3 * **Target**: macOS When using `Electron.Menu.SetApplicationMenu` to replace the default Electron menu, you cannot include a menu item with the `undo` menu role. Doing so results in the following error: ``` Uncaught Exception: TypeError: Invalid template for MenuItem: must have at least one of label, role or type at Function../lib/browser/api/menu.js.Menu.buildFromTemplate (electron/js2c/browser_init.js:1918:11) ``` Steps to Reproduce: 1. In Startup.cs, create a menu template like this: ``` MenuItem[] menu = new MenuItem[] { new MenuItem { Label = "File", Submenu = new MenuItem[] { new MenuItem { Role = MenuRole.close } }}, new MenuItem { Label = "Edit", Submenu = new MenuItem[] { new MenuItem { Role = MenuRole.undo }, new MenuItem { Role = MenuRole.redo }, new MenuItem { Type = MenuType.separator }, new MenuItem { Role = MenuRole.cut }, new MenuItem { Role = MenuRole.copy }, new MenuItem { Role = MenuRole.paste } }} }; ``` 2. Before calling `CreateWindowAsync`, attempt to use the template as the application menu: ``` Electron.Menu.SetApplicationMenu(menu); ```
claunia added the bug label 2026-01-29 16:39:56 +00:00
Author
Owner

@GregorBiswanger commented on GitHub (Apr 18, 2020):

Fixed in Electron.NET Version 8.31.1 - Thanks for your pull request 🥳

@GregorBiswanger commented on GitHub (Apr 18, 2020): Fixed in Electron.NET Version 8.31.1 - Thanks for your pull request 🥳
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/Electron.NET#451