Search code examples
c#visual-studio-addinsvisual-studio-package

Adding a tool window to an exisiting VS extension package - FindToolWindow fails


I have a VS package with no tool windows, and now I want to add a first tool window to it. This is what I've done:

  1. Created an empty class derived from ToolWindowPane.
  2. Added Guid attribute to this class. I've generated a new GUID with the Visual Studio built-in tool.
  3. Added 2 attributes to the main package class:
    [ProvideToolWindow(typeof(MainToolWindow))]
    and
    ([ProvideToolWindowVisibility(typeof(MainToolWindow), VSConstants.UICONTEXT.SolutionExists_string)]

  4. Called ToolWindowPane MyWindow = this.FindToolWindow(typeof(MainToolWindow), 0, true);

This results in an exception:

Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED))

What did I miss?


Solution

  • The exception was caused by content being null. Adding this to the window constructor does the trick:

    Content = new System.Windows.Controls.UserControl();