locked
Exception in Creating a dockable toolwindow from a Visual Studio .NET add-in RRS feed

  • Question

  • Following is my Connect.cs class that I used to add code of my addin. At the moment it does two main tasks. that are adding a button to the solution explorer's 'Web Item' menu (that is to execute the addin). and the other task is adding a button to standard toolbar to view a dockable tool window where i can add my own error/warning etc later. 

    I could build it but when i run visual studio, I am getting this exception "System.ArgumentException:A command with that name already exists at EnvDTE80.Commands2.AddNamedCommand2(AddIn AddInInstance, String Name, String ButtonText,String tooltip,Boolean MSOButton,Object Bitmap, Object[]& ContextUIGUIDs,Int32 vs...........) and it points to my OnConnection() method"

    PLEASE help me telling what's wrong with this. 

    I also have to mention that I made a sample add-in to see the above code working and giving me a toolwindow as expected. It worked fine and i could click the newly created button and view a toolwindow. Later, I deleted the Add-in project folder and the AddIn file both and started trying this in the AddIn project that I am suppose to work. 

    I got the source details from here,

    http://www.mztools.com/articles/2006/MZ2006007.aspx

     

    const string TOOLWINDOW_GUID = "{6CCD0EE9-20DB-4636-9149-665A958D8A9A}";

    says that we need to create a Unique GUID for each tool window. IS there where I am going wrong. If I tried the same code in two diffrrent add-in projects running in the same machine, what are the main considerations.

    by the way, how can we mention a unique GUID?

    Saturday, June 8, 2013 4:54 AM

Answers

  • Thanks for the reply. Actually since I had trouble with the code, I tried out the same in a different machine with a fresh copy of my working addIn following the instructions in your link. did some changes to fit for my purpose and it works fine. the code that was giving trouble is replaced. 

    the blog at http://www.mztools.com was really useful

    Sunday, June 9, 2013 8:24 AM

All replies

  • Hi,

    If you get "System.ArgumentException:A command with that name already exists at EnvDTE80.Commands2.AddNamedCommand2" is because you are not checking that the command already exists before adding the command.

    My sample (http://www.mztools.com/articles/2006/MZ2006007.aspx) checks the command existence so it should not cause that exception:

    // Try to retrieve the command, just in case it was already created, ignoring the
    // exception that would happen if the command was not created yet.
    try
    {
       myCommand = applicationObject.Commands.Item(addInInstance.ProgID + "." + MY_COMMAND_NAME, -1);
    }
    catch
    {
    }

    // Add the command if it does not exist
    if (myCommand == null)
    {
       myCommand = applicationObject.Commands.AddNamedCommand(addInInstance,
          MY_COMMAND_NAME, MY_COMMAND_CAPTION, MY_COMMAND_TOOLTIP, true, 59, ref contextUIGuids,
          (int)(vsCommandStatus.vsCommandStatusSupported | vsCommandStatus.vsCommandStatusEnabled));
    }

    Can you post your code?

    About Guids, each toolwindow of each add-in should have a different Guid. You can create a new Guid using the Tools, Create GUID menu of Visual Studio, which in fact is an external tool that points to c:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\bin\NETFX 4.0 Tools\guidgen.exe. The guidgen.exe tool can be in several locations (SDKs).


    MZ-Tools: Productivity add-ins for Visual Studio: http://www.mztools.com. My blog about developing add-ins: http://msmvps.com/blogs/carlosq/

    Sunday, June 9, 2013 8:15 AM
  • Thanks for the reply. Actually since I had trouble with the code, I tried out the same in a different machine with a fresh copy of my working addIn following the instructions in your link. did some changes to fit for my purpose and it works fine. the code that was giving trouble is replaced. 

    the blog at http://www.mztools.com was really useful

    Sunday, June 9, 2013 8:24 AM