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 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, Visual Studio Code and Azure DevOps.
We Are
  • onlyutkarsh
    Utkarsh Shigihalli
    Microsoft MVP, Technologist & DevOps Coach

  • arora_tarun
    Tarun Arora
    Microsoft MVP, Author & DevOps Coach at Avanade

Do you like our posts? Subscribe to our newsletter!
Our Book