Cannot instantiate EnvDTE.DTEClass class

  • Thread starter Thread starter George Jordanov Ivanov
  • Start date Start date
G

George Jordanov Ivanov

Hello,

I am currently developing an add-in for Visual Studio .NET 7.0, 7.1 and 8.0.
I am using Visual Studio .NET 2003 to develop it and C# as a programming
language. I have installed Microsoft .NET framework 1.0, 1.0 and 2.0 on my
machine.

Normally, my add-in registers his own commands, bound to UI command bar
buttons. To perform a clean uninstall, I added an Installer class, in whose
Uninstall method I am trying to delete the commands, registered by my
add-in. But in this Installer class I don't have a valid instance of DTE
object, so I have to create it. The class which represents the Visual Studio
..NET IDE is EnvDTE.DTEClass
class. Unfortunately, when I am trying to instantiate it, I get the
following exception:

System.Runtime.InteropServices.COMException (0x80040154): COM object with
CLSID {3C9CFE1E-389F-4118-9FAD-365385190329} is either not valid or not
registered.

Now, I checked whether there is a such COM server with CLSID
{3C9CFE1E-389F-4118-9FAD-365385190329} registered in HKEY_CLASSES_ROOT\CLSID
(that is there is a well-formed key under
HKEY_CLASSES_ROOT\CLSID\{3C9CFE1E-389F-4118-9FAD-365385190329} having the
required InprocServer32 subkey, pointing to:
EnvDTE, Version=7.0.3300.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a

I also created a standalone Windows forms application that actually tries to
create a new instance of DTEClass class, but still I have the same
exception. That is to show that this error is not caused by Windows
Installer or something - this is obviously a generic error.

I found an article in Internet about the same problem, but still it hasn't
any prescribed solution for it. Does anyone has an idea how I can solve this
issue?
Regards,
George Jordanov Ivanov
 
Hi,

I use "VisualStudio.DTE.7", "VisualStudio.DTE.7.1" and
"VisualStudio.DTE.8.0"

Also,can you use the RegMon tool
(http://www.sysinternals.com/Utilities/Regmon.html) to spy the registry
activity?

--

Best regards,

Carlos J. Quintero

MZ-Tools: Productivity add-ins for Visual Studio 2005, Visual Studio .NET,
VB6, VB5 and VBA
You can code, design and document much faster in VB.NET, C#, C++ or VJ#
Free resources for add-in developers:
http://www.mztools.com
 
Hi George,

Thanks for your posting here. Regarding on this issue, I've also noticed
your another thread in the microsoft.public.vsnet.ide newsgroup. I've
posted my response there. I'd appreciate if you have a look there.


Thanks for your understanding!

Best regards,

Gary Chang
Microsoft Community Support
--------------------
Get Secure! ¡§C www.microsoft.com/security
Register to Access MSDN Managed Newsgroups!
http://support.microsoft.com/default.aspx?scid=/servicedesks/msdn/nospam.asp
&SD=msdn

This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hi Gary,

Thanks for you reply. Indeed, when I use Marshal.GetActiveObject(), I am
able to instantiate the DTE object for Visual Studio .NET 2003. However,
while trying to get a instance of Visual Studio 8.0 (which I have currently
installed, this is the official professional release), I ended up with the
following exception:

"System.Runtime.InteropServices.COMException (0x800401E3): Operation
unavailable\r\n at
System.Runtime.InteropServices.Marshal.GetActiveObject(Guid& rclsid, UInt32
reserved, Object& ppunk)\r\n at
System.Runtime.InteropServices.Marshal.GetActiveObject(String progID)\r\n
at EnvDTEDTEClassTest.Form1.btnCreateDTEClassInstance_Click(Object sender,
EventArgs e) in

Using RegMon.exe , it see that it finds correctly the CLSID of the
VisualStudio.DTE.8.0 COM object, but however, obviously something else after
that is getting wrong. Any ideas how I can solve this now?

Thanks for your help!
Regards,
George Jordanov Ivanov

P.S. Big thanks to Carlos, who gave me the idea to use RegMon.exe to see
what is going on in the registry. Really this tool was very useful for the
problem I had. Thanks again, man!
 
I know what was the problem with GetActiveObject() and Visual Studio 8.0.
GetActiveObject() actually returns a valid instance only if there is a
running instance of Visual Studio. Accordingly, if there is no such
instance, there is nothing to return. However, the exception that I received
(i.e. Operation unavailable) is somehow misleading.

So if you want to "create" a instance of DTE object for Visual Studio 8.0,
you need the following code (in C#):
dteInst80 =
(EnvDTE.DTE)Microsoft.VisualBasic.Interaction.CreateObject("VisualStudio.DTE.8.0",
"");

In order to run it, you need to add a reference to Microsoft Visual Basic
..NET Runtime assembly.

Actually, I found a pretty good article about how to access DTE object in
MSDN. Here it is:
[Referencing the DTE Object]
http://msdn.microsoft.com/library/d...s/vsintro7/html/vxconreferencingdteobject.asp

I guess that we have solved the problems with this mysterious DTE object
now! :)

Thank you all!
Greets,
George Jordanov Ivanov

George Jordanov Ivanov said:
Hi Gary,

Thanks for you reply. Indeed, when I use Marshal.GetActiveObject(), I am
able to instantiate the DTE object for Visual Studio .NET 2003. However,
while trying to get a instance of Visual Studio 8.0 (which I have
currently installed, this is the official professional release), I ended
up with the following exception:

"System.Runtime.InteropServices.COMException (0x800401E3): Operation
unavailable\r\n at
System.Runtime.InteropServices.Marshal.GetActiveObject(Guid& rclsid,
UInt32 reserved, Object& ppunk)\r\n at
System.Runtime.InteropServices.Marshal.GetActiveObject(String progID)\r\n
at EnvDTEDTEClassTest.Form1.btnCreateDTEClassInstance_Click(Object sender,
EventArgs e) in

Using RegMon.exe , it see that it finds correctly the CLSID of the
VisualStudio.DTE.8.0 COM object, but however, obviously something else
after that is getting wrong. Any ideas how I can solve this now?

Thanks for your help!
Regards,
George Jordanov Ivanov

P.S. Big thanks to Carlos, who gave me the idea to use RegMon.exe to see
what is going on in the registry. Really this tool was very useful for the
problem I had. Thanks again, man!

"Gary Chang[MSFT]" said:
Hi George,

Addition to Carlos's response, if you target on the Visual Studio 2003's
IDE, you may use the following code snippet to instantiate the VS2003's
EnvDTE's object:

EnvDTE.DTE myDTE;
myDTE =
(EnvDTE.DTE)Microsoft.VisualBasic.Interaction.CreateObject("VisualStudio.DTE
7.1", "");

-or-
//Get an instance of the currently running Visual Studio .NET IDE

EnvDTE.DTE dte;
DTE =
(EnvDTE.DTE)System.Runtime.InteropServices.Marshal.GetActiveObject("VisualSt
udio.DTE.7.1")


Thanks!

Best regards,

Gary Chang
Microsoft Community Support
--------------------
Get Secure! ¡§C www.microsoft.com/security
Register to Access MSDN Managed Newsgroups!
http://support.microsoft.com/default.aspx?scid=/servicedesks/msdn/nospam.asp
&SD=msdn

This posting is provided "AS IS" with no warranties, and confers no
rights.
 
Back
Top