How to get type of COM object

user65199 picture user65199 · Sep 15, 2009 · Viewed 17.1k times · Source

I am referencing a COM library in Visual Studio, so it has automatically created the corresponding Interop assembly for me. I would like to do a GetType() on these com objects, but they always return System.__ComObject. Querying them for an interface works though:

bool isOfType = someComeObject is ISomeComObject; //this works

But what I really want is this to return the actual type of the com object:

Type type = someComeObject.GetType(); //returns System.__ComObject :-(

Does anyone know how to do what I want to do?

Answer

Darin Dimitrov picture Darin Dimitrov · Sep 15, 2009

Add reference to Microsoft.VisualBasic.dll and then:

Microsoft.VisualBasic.Information.TypeName(someCOMObject)

MSDN reference here.