Bobby DeRosa

I've got a managed package that is sensitive to the project type and doesn't need to be visible if the loaded project is not said type (i.e. WebProject).

In my CTC file, I've defined a menu command bar to be displayed along the main menu bar IDG_VS_MM_TOOLSADDINS, (File, Tools, Debug, Help, etc). Its flags are set to DynamicVisibility | DefaultInvisible.

When the package is initialized, it checks for an appropriate project type and if so, makes itself visible. When I attempt to set the Visible property of the package's command bar, I get a tasty HRESULT exception:

Code Snippet

CommandBar cmd = ((CommandBars)appObject.CommandBars)["MyMenuName"];
if(cmd != null)
cmd.Visible = true; //throws error here


Error: "Error HRESULT E_FAIL has been returned from a call to a COM component."

Error Code: -2147467259

I'd be grateful for any suggestions or tips in getting further - I've researched this a bit and can't find much info related to this specific issue.

Cheers,


Re: Visual Studio Extensibility Setting CommandBar Visible throws error

Ed Dore

Hi Bobby,

Where exactly are you invoking this code from

Also, you might want to consider adding a ProvideAutoLoad attribute to your package object, and utilize the VISIBILITY_SECTION of your .CTC file to control the visibility of your menu instead. This way, you don't need to programatically show/hide the menu yourself.

Sincerely,






Re: Visual Studio Extensibility Setting CommandBar Visible throws error

Bobby DeRosa

Hi Ed,

Thanks for the response & suggestions.

This code is invoked when a web site project or web application project is loaded - which is usually in ProjectAdded or SolutionOpened events.

Also, I checked out the VISIBILITY_SECTION documentation but it didn't seem to have the conditional options I need - the closest was UICONTEXT_SolutionExists but I really need an option to toggle visibility on a specific project and/or extender (for WAP).

Cheers,

Bobby





Re: Visual Studio Extensibility Setting CommandBar Visible throws error

Ed Dore

Hi Bobby,

It's just a matter of figuring out what the proper context guid is. Most of the project specific ones aren't documented anywhere. I'll see if I can track down the appropriate ones for WebSite and WAP projects, and post back on this topic. Are there any other project types where you need to ensure these menu items are visible

Thanks,






Re: Visual Studio Extensibility Setting CommandBar Visible throws error

Bobby DeRosa

Hey Ed,

Just Web Sites & WAP.

Much Appreciation,

Bobby





Re: Visual Studio Extensibility Setting CommandBar Visible throws error

Bobby DeRosa

Hey Ed,

Just curious if you'd had a chance to look up those context GUID's for Web Site projects and Web Application Projects.

Also, I'm still curious as to why setting the visibility of a top-level menu would throw an exception. *Should* this normally work Or is the thrown exception an expected behavior.

Cheers,

Bobby