Hi all -
I posted a message here yesterday about a cast from EnvDTE.Project to
VSLangProj.VSProject failing. I now have a reproducible snippet of code (see
below). The thing is, this only fails on my Windows XP laptop - on two
different Win 2000 machine it runs fine. If similar code is called from an
add-in on the Win XP machine, everything runs fine. I'm suspecting it has
something to do with the way I'm creating the DTE instance, but can't be
sure - any idea?
TIA -
Dan
Dim oType As System.Type
Dim oDTE As EnvDTE.DTE
'Get a type for the DTE object
oType = System.Type.GetTypeFromProgID("VisualStudio.DTE.7.1")
'Create it and cast
Dim oObj As Object = System.Activator.CreateInstance(oType, True)
oDTE = CType(oObj, EnvDTE.DTE)
'Open any solution with at least one project
Call oDTE.ExecuteCommand("File.OpenSolution", """PLACE ANY FULL SOLUTION
PATH HERE""")
'Find the first project in the solution and attempt to cast to VSProject
Dim oProject As EnvDTE.Project = oDTE.Solution.Item(1)
Dim oVSProject As VSLangProj.VSProject
Try
oVSProject = oProject.Object
'The cast worked, prove it.
Call MsgBox("Cast succeeded. Project has " & oVSProject.References.Count & "
references.")
Catch ex As Exception
Call MsgBox("Error: " & ex.Message)
End Try
oDTE.Quit()
Carlos J. Quintero [MVP] - 14 Oct 2004 14:57 GMT
Ideas:
- Try using "VisualStudio.DTE.7" (VS.NET 2002), just for testing.
- Compare the versions of the following DLLs:
EnvDTE.dll (C:\WINNT\Microsoft.NET\Framework\v1.xxxx)
VSLangProj.dll (C:\Archivos de programa\Microsoft Visual Studio
.NET\Common7\IDE\PublicAssemblies)
in both machines.

Signature
Carlos J. Quintero (Visual Developer - .NET MVP)
The MZ-Tools all-in-one add-in, now for .NET: http://www.mztools.com
> Hi all -
> I posted a message here yesterday about a cast from EnvDTE.Project to
[quoted text clipped - 48 lines]
>
> oDTE.Quit()
Dan - 14 Oct 2004 19:50 GMT
Carlos -
Thanks for the response.
The versions of both dlls is 7.0.9466.0 on both machines.
I don't have VS 2002 installed on either machine. Why did you suggest
checking it against VS 2002?
Thanks -
Dan
> Ideas:
>
[quoted text clipped - 62 lines]
> >
> > oDTE.Quit()
Carlos J. Quintero [MVP] - 15 Oct 2004 10:06 GMT
Just for seeing if IDE version makes a difference...

Signature
Carlos J. Quintero (Visual Developer - .NET MVP)
The MZ-Tools all-in-one add-in, now for .NET: http://www.mztools.com
> Carlos -
> Thanks for the response.
[quoted text clipped - 6 lines]
> Thanks -
> Dan