1

I am trying to create a Visual Studio instance using :

EnvDTE80.DTE2 dte2;
dte2 = (EnvDTE80.DTE2)System.Runtime.InteropServices.Marshal.GetActiveObject("VisualStudio.DTE.12.0");

And I am always having the exception "Invalid Class String" so I assume that the problem is "VisualStudio.DTE.12.0". But I am working on Visual Studio 2013 12.0.30501, I also tried to put only "VisualStudio.DTE" to get the most recent version, and same exception.

Also, I tried the other way :

Type t = Type.GetTypeFromProgID("VisualStudio.DTE.12.0", true);
dte2 = (EnvDTE80.DTE2)System.Activator.CreateInstance(t, true);

The problem is still there, I am running a bit out of idea... Is it really an invalid string error ?

Geoffrey
  • 11
  • 1
  • 2
  • No, that's the correct ProgID if you have VS2013. Your registry must be broken, use Regedit.exe to have a look at HKEY_CLASSES_ROOT\VisualStudio.DTE.12.0. With the expectation that you cannot find it. – Hans Passant Jul 01 '14 at 10:27
  • This is correct, I can't find the HKEY_CLASSES_ROOT\VisualStudio.DTE.12.0 in regedit. How am I supposed to "create" it ? – Geoffrey Jul 01 '14 at 15:04
  • Your machine is broken. Heavens knows what else disappeared. Feel free to panic. Re-running the VS installer might work. – Hans Passant Jul 01 '14 at 15:11
  • Well, thank you very much I will try to solve it this way ! – Geoffrey Jul 01 '14 at 15:16

1 Answers1

1

If you are using Visual Studio 2013 Express this works to fix it:

Type t = Type.GetTypeFromProgID("WDExpress.DTE.12.0", true);
var x = (EnvDTE80.DTE2)System.Activator.CreateInstance(t, true);
Flexo
  • 87,323
  • 22
  • 191
  • 272
MarmotJam
  • 11
  • 1