'Value does not fall within the expected range' error while adding toolbar to toolwindow

Dec 24, 2015 | Utkarsh Shigihalli Utkarsh Shigihalli

VisualStudio Extensions Exception

Hello, this is going to be a small post. In one of my Visual Studio extension, I was trying to add a toolbar to the toolwindow. Everything compiled just fine and all seemed perfect. However, as soon as I tried to open the toolwindow (with toolbar) I was getting “Value does not fall within the expected range” error.

Alt text

Obviously, error did not give me much details on what caused the error. Break on CLR exceptions setting lead me to this line.

1
ToolWindowPane window = this.package.FindToolWindow(typeof(MyToolWindow), 0, true);

So, Assuming an issue with my declarions of toolwindow, I verified GUID’s used, other declarations made in my VSCT file. All looked correct but still the same error.

After numerous debug sessions, found out that Visual Studio throws this error when the toolbar you are adding does not have any command added to it. That is, whenever you add a toolbar to the toolwindow, make sure you add at least one button (command) to it.

So adding a Button element resolved the issue for me.

About author
Utkarsh Shigihalli
Utkarsh Shigihalli
Utkarsh is passionate about software development and has experience in the areas of Azure, Azure DevOps, C# and TypeScript. Over the years he has worked as an architect, independent consultant and manager in many countries including India, United States, Netherlands and United Kingdom. He is a Microsoft MVP and has developed numerous extensions for Visual Studio and Azure DevOps.
Comments