none
Visual Studio 2010 throwing COM exception on commandBarPopUp.getEvents()

    Question

  • hello all,

    I have created a visual studio add-in which is used for code reviewing purpose. I had created installers and everything was working fine in visual studio 2008.

    But recently i got a requirement to make my add-in tool to work in visual studio 2010, But there i am facing a major problem in loading my addin in visual studio 2010 .

    Whenever i load the project there is exception at this line.

     popUpEvents = (CommandBarEvents)applicationObject.Events.get_CommandBarEvents(codeReviewToolPopup);

    Exception details : "Member not found. (Exception from HRESULT: 0x80020003 (DISP_E_MEMBERNOTFOUND))"

    but same line was working in vs2008!!!!

     

    I made extensive search on this and found that it is a bug in VS2010 !!!! Everywhere they have mentioned there is a workaround but i was unable to find out what was workaround.

    Since this is very critical i am hoping for a early reply

     

    Thanks in advance,

    Sandeep Krishnamurthy


    sandeep.k
    Wednesday, February 16, 2011 4:12 AM

Answers

All replies

  • >I made extensive search on this and found that it is a bug in VS2010 !!!!

    It isn't clear why you have 4 exclamation points here, there are in fact bugs in VS 2010, there were bugs in 2008, there will be bugs in 2011. You can't have a software product as complex as VS and have no bugs, that is a utopian fantasy.  The fact that HUGE parts of the VS shell (i.e. the commanding and windowing system) were basically re-written in 2010 also leads one to conclude there may indeed be bugs there, it wasn't purposeful.

    >Everywhere they have mentioned there is a workaround but i was unable to find out what was workaround.

    Pointing us to these locations where they claim there is some work around might help with an answer.  I am not on corp net at the moment so I can't look at the code or any open bugs, I am not sure off hand about this bug so I can't confirm or deny it.  What are you using the events for exactly?  That may help in finding a work around.

    Ryan

     

    Wednesday, February 16, 2011 7:14 AM
    Moderator
  •  

    hi ryan,

     

    Sorry if i have made a wrong statement in saying bug in VS2010 , In fact i am big fan and very grateful to Visual Studio team because it has greatly reduced development pain on developers like us.

     

    Link where they have mentioned there is work around :

    http://stackoverflow.com/questions/2977704/do-you-have-ideas-for-a-workaround-for-this-known-bug-in-visual-studio-2010s-add

    http://connect.microsoft.com/VisualStudio/feedback/details/524335/events-get-commandbarevents-exception-on-submenus-reproducible-bug-addin

    Context in which i need that event handler :

     

    I am developing a code review tool which is a addin for visual studio.

    I have added a command bar pop up menu for my tool (similar to help, tools etc..)

    I have a two command bar pop-up option for my tool command bar menu.(one command bar pop up to list all developer related options, second command bar pop up to list all reviewer related options)

    Now i want to have click event on that main command bar pop up option (i.e., handle click event on my command bar pop and list all drop down options)

    there i have used following code snipets

     

    private
     CommandBarPopup codeReviewToolPopup;

    private CommandBarEvents popUpEvents;

    Microsoft.VisualStudio.CommandBars.CommandBar menuBarCommandBar=((Microsoft.VisualStudio.CommandBars.CommandBars)applicationObject.CommandBars)["MenuBar" ];
    codeReviewToolPopup = (CommandBarPopup)menuBarCommandBar.Controls.Add(MsoControlType.msoControlPopup, Type.Missing, Type.Missing, menuBarCommandBar.Controls.Count - 3, true );


    popUpEvents = (CommandBarEvents)applicationObject.Events.get_CommandBarEvents(codeReviewToolPopup);




    popUpEvents.Click += new _dispCommandBarControlEvents_ClickEventHandler(CodeReviewTool_Click);

     


     

    i will get following exception in the highlighted line.

     

    "COM exception was handled by the code"

    "Member not found. (Exception from HRESULT: 0x80020003 (DISP_E_MEMBERNOTFOUND))"

    Exception details:

    System.Runtime.InteropServices.COMException was unhandled by user code
      Message=Member not found. (Exception from HRESULT: 0x80020003 (DISP_E_MEMBERNOTFOUND))
      Source=EnvDTE
      ErrorCode=-2147352573
      StackTrace:
           at EnvDTE.Events.get_CommandBarEvents(Object CommandBarControl)
           at EnableCodeReviewTool.Connect.EnableCodeReviewTool() in D:\CodeReviewToolCode\SchneiderElectric.CodeReview.CodeReviewToolAddin\Connect.cs:line 180
           at EnableCodeReviewTool.Connect.OnConnection(Object application, ext_ConnectMode connectMode, Object addInInst, Array& custom) in D:\CodeReviewToolCode\SchneiderElectric.CodeReview.CodeReviewToolAddin\Connect.cs:line 135
      InnerException:

    Thanks in advance,

    sandeep k

     


    sandeep.k
    Wednesday, February 16, 2011 8:10 AM
  • >Sorry if i have made a wrong statement in saying bug in VS2010 

    Not the wrong statement, you just seemed shocked that there could be a bug in VS :)  I wish it was the case there was no bugs, but unfortunately there are :(

    >http://stackoverflow.com/questions/2977704/do-you-have-ideas-for-a-workaround-for-this-known-bug-in-visual-studio-2010s-add

    I was actually the person who answered this question :)  The user was using the popup event as a way to update the state of all his commands. I told him that was unnecessary and if his AddIn implemented IDTCommandTarget then he would be called to update the state of his commands at the same time that commands are updated for all of VS, and specifically it would happen right before the menu was displayed, which was what he wanted.

    If you are also using the click event as an update trigger, though this may have worked fine in 2008, it was always the wrong way to do it as the shell has a mechanism for command updates you should be using.  The IDTCommandTarget approach works in 2010, and 2008 and 2005 as far as I know.

    Ryan

    Wednesday, February 16, 2011 4:01 PM
    Moderator
  • Hello,

    See:

    HOWTO: Controlling the state of command in a Visual Studio add-in

     


    MZ-Tools: Productivity add-ins for Visual Studio: http://www.mztools.com. My blog about developing add-ins: http://msmvps.com/blogs/carlosq/
    Wednesday, February 16, 2011 10:55 PM
    Moderator
  • Hi carlos and ryan,

    the scenario where i am using that click event is as below:

    "I need several configuration information from users before using my addin. For example my addin has 3 dropdown menu options as shown below

    assume visual studio picture is as shown below

    file edit.........tools  myaddin

                               1.Developer -> some menus

                               2.Reviewer-> some menus

                               3.Configuration.

     

    Now in order to enable developer and reviewer menus i have used a logic to catch click event on "myddin" command bar popup and then call a method in event handler which checks if configuration is done or not. If configuration is done i will enable "developer" and "reviewer" options.

    So here i have not used "QueryStatus" or "Exec" methods.

    Now i hope you got in which scenario i am using that command bar click event handler.

    Here one more problem is

    "I can  call the method which checks if configuration is done or not in on connection method itself but in a scenario where

    -User click on my add-in

    -In onConnect i wil find config is not done so i disable "developer" and "reviewer" options.

    -User configures now.

    -but since i have already disabled two options in onConnect method i wil not be able to enable two options on fly

    ( if i handle click event on command bar menu of addin i can check if config is done whenever user clicks)

    Is there any workaround to achieve this functionality? Thanks in advance

     

    Thanks and regards,

    Sandeep K


    sandeep.k
    Thursday, February 17, 2011 3:03 AM
  • >So here i have not used "QueryStatus" or "Exec" methods.

    Yes, what I am saying is you SHOULD be using IDtCommandTarget, using a parent menu level click handler (any 'click' handlers really) is somewhat of a hack.

    Ryan

    Thursday, February 17, 2011 5:04 PM
    Moderator
  • Hello,

    The article that I provided covers your scenario. The QueryStatus approach works. See it this way: QueryStatus is called before showing your menu. No need for the Click event.


    MZ-Tools: Productivity add-ins for Visual Studio: http://www.mztools.com. My blog about developing add-ins: http://msmvps.com/blogs/carlosq/
    Thursday, February 17, 2011 7:04 PM
    Moderator