Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Trying to check the type of some Elements if they are (ITextElement , MarkerElement), when i try .getType() function it returns always "System._COM_object".

How i could get the type of an object if i don't know its type before ? because i could only detect the types that i pretend using (obj as Interface) != null.

but for the types that i don't pretend i get always null from (obj as Interface) .

Any help please.

share|improve this question
up vote 8 down vote accepted

In ArcObjects, like other COM-based libraries, interface testing is the main way you determine the type (using that term loosely) of object you have:

if (element is ITextElement):
    // Do something
else if (element is IMarkerElement):
    // Do something else

Another thing you can do is, if the object implements IPersist, you can get its CLSID using GetClassID, and, from there (if desired), you can get its ProgID using the WinAPI ProgIDFromCLSID function. This is useful for cases where the object has no other indicative interfaces.

Lastly, and I've never used this myself as it seems very unwieldy and potentially very slow, is to use reflection to query interface the object against every interface in an assembly to see which interfaces it supports:

    IntPtr iunkwn = Marshal.GetIUnknownForObject(pWorkspace);
    // enum all the types defined in the interop assembly
    System.Reflection.Assembly objAssembly =
    Type[] objTypes = objAssembly.GetTypes();
    // find the first implemented interop type
    foreach (Type currType in objTypes)
        // get the iid of the current type
        Guid iid = currType.GUID;
        if (!currType.IsInterface || iid == Guid.Empty)
            // com interop type must be an interface with valid iid
        // query supportability of current interface on object
        IntPtr ipointer = IntPtr.Zero;
        Marshal.QueryInterface(iunkwn, ref iid, out ipointer);
        if (ipointer != IntPtr.Zero)
            string str =currType.FullName;

(Source: Re: Getting the real COM class name)

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.