'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.

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 more than 12 years of work experience in the areas of Azure, VSTS, C# and TypeScript. He has developed numerous extensions for Visual Studio and Visual Studio Team Services. He is currently working as a Consultant in the United States.