-1

I'm working on an extension and had to delete a custom command then re add it. Now when I try to run the extension I get an error saying

There is already a command handler for the menu command.

Has anyone come across this before? Any ideas how to fix? I've tried creating a new GUID and changing the commandId but no luck.

Error Output: An exception of type 'System.ArgumentException' occurred in System.Design.dll but was not handled in user code

Additional information: There is already a command handler for the menu command '4fd442a6-1a00-47ee-b98d-f11b0faafbe2 : 256'.

From the vsct file:

 <GuidSymbol  name="guidVSProximityMenuPackageCmdSet3" value="{4FD442A6-1A00-47EE-B98D-F11B0FAAFBE2}">

  <IDSymbol name="ProximityProjectExplorerGroup" value="4128" />
  <IDSymbol value="256" name="cmdidGetNugetVersionCommand" />

 </GuidSymbol>

From the command.cs file:

/// <summary>
    /// Command ID.
    /// </summary>
    public const int CommandId = 256;

    /// <summary>
    /// Command menu group (command set GUID).
    /// </summary>
    public static readonly Guid CommandSet = new Guid("4FD442A6-1A00-47EE-B98D-F11B0FAAFBE2");

The exception is thrown from this method (located in the command.cs file)

/// <summary>
    /// Initializes a new instance of the <see cref="GetNugetVersionCommand"/> class.
    /// Adds our command handlers for menu (commands must exist in the command table file)
    /// </summary>
    /// <param name="package">Owner package, not null.</param>
    private GetNugetVersionCommand(Package package)
    {
        if (package == null)
        {
            throw new ArgumentNullException("package");
        }

        this.package = package;

        OleMenuCommandService commandService = this.ServiceProvider.GetService(typeof(IMenuCommandService)) as OleMenuCommandService;
        if (commandService != null)
        {
            var menuCommandID = new CommandID(CommandSet, CommandId);
            var menuItem = new MenuCommand(this.MenuItemCallback, menuCommandID);
            commandService.AddCommand(menuItem);
        }
    }

On the commandService.AddCommand(menuItem); line when I try to call a different command from the menu in Visual Studio.

Thanks again for any help!

cbutler
  • 833
  • 13
  • 36
  • 1
    I think you need to add code samples. Otherwise this won't be reproduceable at all – rbr94 Dec 06 '16 at 13:16
  • 1
    It's impossible to help with no information at all. Most likely you didn't remove the existing command - did you check any error codes? Results? At least post the code you use to remove the command – Panagiotis Kanavos Dec 06 '16 at 13:35
  • According to your code, it seems ok, please create a new project and copy related code to new project, which use new Guid. Check if it works. – Zhanglong Wu - MSFT Dec 07 '16 at 02:40
  • if the issue still exist, please share a simple demo which could reproduce the issue via OneDrive. – Zhanglong Wu - MSFT Dec 07 '16 at 02:58
  • @ColeWu-MSFT Thanks for the suggestion. I am trying to avoid doing that if possible but I will as a last resort. I would really like to figure out why it's happening in the first place. – cbutler Dec 07 '16 at 07:17
  • According to your description, it seems that it is a old version of package cause the issue, please uninstall all the command package via (Tools -> Extensions and Updates -> find the vsix package -> click uninstall). – Zhanglong Wu - MSFT Dec 22 '16 at 02:59

1 Answers1

1

Have you tried resetting the Experimental Instance? There should be a batch file in your start menu entitled Reset the Visual Studio 2015 Experimental Instance. Run this, and it'll make sure that everything's reset back to the default state. I'm guessing what happened here is that you changed the identifier of your extension package, and the new one is being installed alongside the previous one, which is still providing a handler for the command you're attempting to add.

PfhorSlayer
  • 1,337
  • 9
  • 14