Adding a button from an add-in to a TOC context menu

Discussion created by dbrandon on Mar 25, 2014
Hey all:

I would like to add a button to a group layer context menu in the table of contents.  The button is from an add-in that also contains an extension.  Should be straight-forward enough.  The extension monitors the IActiveViewEvents_Event events and checks for a group layer being added by a specific name.  When a layer is added, the IActiveViewEvents_ItemAddedEventHandler() is fired and calls a method that adds the button to the group layer context menus if the name is right.  That mechanism is working.  The snippet of code that is failing is below:

if (String.Compare(topLayer.Name, "Testing") == 0)
    // Set a uid for the group layer context menu.
    UID gUID = new UID();
    gUID.Value = "esriArcMapUI.GroupLayerContextMenu";     // "{863A0D98-73DC-4331-8658-ED0E22247E36}"

    // Get the command bar denoting that context menu.
    ICommandBar groupLayerContextMenu = ArcMap.Application.Document.CommandBars.Find(gUID, false, false) as ICommandBar;

    // If there is a group layer context menu.
    if (groupLayerContextMenu != null)
        // Change the UID to the add-in command.
        gUID.Value = ThisAddIn.IDs.TestContextMenuButton;

        ICommandItem cmd = groupLayerContextMenu.Find(gUID);

        if (cmd == null)
            cmd = groupLayerContextMenu.Add(uid, ref missing);                 // 'Command not available' error thrown here...

To me, it seems that the command is not found because ICommandBar.Add(uid) is trying to dig for it in the registry but because it resides in an add-in it has not been added to the registry.  Is there another way to add a button, or any item for that matter, when it lives in an add-in?  Or am I missing something simple?