||Carlos J. Quintero (Microsoft MVP)
||Microsoft Visual Studio 2005
||Microsoft Visual Studio 2008
||Microsoft Visual Studio 2010
||Microsoft Visual Studio 2012
If you have a document with two windows open (such as a code window and a designer
window) and you call DTE.ActiveDocument.ActiveWindow while a toolwindow is active, it returns the first window which was
opened for the document, not the active one.
This is a bug of Visual Studio.
Steps to reproduce the problem:
- Create an add-in with the code below. Do not mark the add-in to load on startup:
|Language: C#|| Copy Code (IE only)|
private DTE2 _applicationObject;
private AddIn _addInInstance;
public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom)
_applicationObject = (DTE2)application;
_addInInstance = (AddIn)addInInst;
if (_applicationObject.ActiveDocument != null)
- Run the add-in project and in the new Visual Studio instance create a Windows Form application project.
- A project is created and the window "Form1.cs [Design]" is active.
- Double-click the form so that a new "Form1.cs" window becomes active (the one with the code)
- Set the focus on the Solution Explorer toolwindow.
- Go to "Tools", "Add-In Manager", and load the add-in.
- The add-in shows "Form1.cs [Design]" as the active window of the active document, instead of "Form1.cs". If a toolwindow (such as the Solution Explorer) doesn't have the focus, the add-in shows "Form1.cs" as expected.
Go back to the 'Resources for Visual Studio .NET extensibility' section for more articles like this