Getting DTE2 reference throws exception

1

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 ?

enter image description here

vsix
envdte
asked on Stack Overflow May 4, 2017 by bbsimonbb

1 Answer

3

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.

answered on Stack Overflow May 4, 2017 by Carlos Quintero

User contributions licensed under CC BY-SA 3.0