BUG: Problems with commandbars of Visual Studio 2005 add-ins after importing settings

Author: Carlos J. Quintero (Microsoft MVP) Applies to: Microsoft Visual Studio 2005
Date: January 2006    

This article explains a couple of problems that appear with the commandbars created by a Visual Studio 2005 add-in after the user executes the "Tools", "Import and Export Settings" wizard to import settings.


This is a bug of Visual Studio 2005.

More Information

Steps to reproduce the problem:

  • Create a Visual Basic 2005 add-in and merge the code below. The add-in creates a toolbar and adds a button from the Help.About command.
Private m_objDTE As DTE
Private m_objCommandBar As CommandBar
Private m_objCommandBarButton As CommandBarButton

Public Sub OnConnection(ByVal application As Object, ByVal connectMode As ext_ConnectMode, _
   ByVal addInInst As Object, ByRef custom As Array) Implements IDTExtensibility2.OnConnection

   Dim colCommandBars As CommandBars
   Dim objCommand As Command


      Select Case connectMode

         Case ext_ConnectMode.ext_cm_AfterStartup, ext_ConnectMode.ext_cm_Startup

            m_objDTE = CType(application, DTE)
            colCommandBars = CType(m_objDTE.CommandBars, CommandBars)
            m_objCommandBar = colCommandBars.Add(Name:="Test", Position:=MsoBarPosition.msoBarTop, _

            objCommand = m_objDTE.Commands.Item("Help.About")

            m_objCommandBarButton = CType(objCommand.AddControl(m_objCommandBar), CommandBarButton)
            m_objCommandBarButton.Style = MsoButtonStyle.msoButtonCaption
            m_objCommandBarButton.Visible = True

            m_objCommandBar.Visible = True

      End Select

   Catch ex As Exception
   End Try

End Sub

Public Sub OnDisconnection(ByVal disconnectMode As ext_DisconnectMode, ByRef custom As Array) _
   Implements IDTExtensibility2.OnDisconnection


      If Not (m_objCommandBar Is Nothing) Then
      End If

   Catch ex As Exception
   End Try

End Sub
  • Run the project, load the add-in and unload it to see that it works correctly.
  • Load the add-in, and execute the "Tools", "Import and Export Settings" wizard.
  • Select "Import selected environment settings" and click the "Next" button.
  • Select "Yes, save my current settings" and click the "Next" button.
  • Select the "Default Settings", "Visual Basic Development Settings" and click the "Next" button.
  • Click the "Finish" button.
  • The new settings are applied. Click the "Close" button.
  • The first bug that you notice is that the toolbar of the add-in has been destroyed, while the wizard should affect only to built-in Visual Studio 2005 commandbars, not to commandbars created by add-ins.
  • If now you go to the Add-in Manager, the add-in is still loaded. If you unload it (to reload it to make its toolbar to reappear) you get COMException (0x800A01A8) at the Microsoft.VisualStudio.CommandBars.CommandBar.Delete procedure.

Go to the 'Visual Studio Extensibility (VSX)' web site for more articles like this (Articles section)