As instructed, I use the following line to get the DTE2 instance in a menu item callback in a VSIX extension.
dte2 = (DTE2)System.Runtime.InteropServices.Marshal.GetActiveObject("VisualStudio.DTE.12.0");
This has started crashing, perhaps since I ported the VSIX to Visual Studio 2017. I get a mystery dialog that says "operation not available", or sometimes "Invalid class string (Exception from HRESULT: 0x800401F3(CO_E_CLASSSTRING))"
What happened ?
Correct way is
EnvDTE80.DTE2 dte2 = base.GetService(typeof(EnvDTE.DTE)) as EnvDTE80.DTE2;
Not to mention that 12.0 is for VS 2013 not for VS 2017.
User contributions licensed under CC BY-SA 3.0