Search code examples
visual-studio-2013envdtecomobject

'The type x exists in both dll' SAME dll + cast to CORRECT object type returns null?


Some info: I'm using .Net 4.5, and trying to extend Visual Studio 2013.

This line of code works fine, I am getting an object

object vce = dte2.GetObject("Microsoft.VisualStudio.TeamFoundation.VersionControl.VersionControlExt");

The type is, according to the watch window: Microsoft.VisualStudio.TeamFoundation.VersionControl.VersionControlExt vce type is VersionControlExt

But, when I try to cast to this type by using this statement

VersionControlExt vceCast = vce as Microsoft.VisualStudio.TeamFoundation.VersionControl.VersionControlExt;

I'm getting null vceCast is null

Weird part:

When I try to cast on watch window, I'm getting this hilarious error message: type exists in both The type 'Microsoft.VisualStudio.TeamFoundation.VersionControl.VersionControlExt' exists in both 'Microsoft.VisualStudio.TeamFoundation.VersionControl.dll' and 'Microsoft.VisualStudio.TeamFoundation.VersionControl.dll'

As you can see - it's the same DLL!

I've tried to use dynamic, and then I got RuntimeBinderInternalCompilerException An unexpected exception occurred while binding a dynamic operation.

List of references I'm using:

enter image description here

My conclusion:

I'm pretty sure that this is happening due to some bad references I've used. any idea how to find them?


Side question: How can I iterate through COM Object like DTE/DTE2 to get info about a 'living' instance and it's properties?


Solution

  • For VS 2013 you need to reference version 12.0.0.0 of the Global Assembly Cache (GAC) of .NET Framework 4.xenter image description here:

    c:\Windows\Microsoft.NET\assembly\GAC_MSIL\Microsoft.VisualStudio.TeamFoundation.VersionControl\v4.0_12.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.TeamFoundation.VersionControl.dll

    And then the cast will be fine.