Interop effects by resolving and instantiating types with ArcObjects

Posted by Marko Apfel on Geeks with Blogs See other posts from Geeks with Blogs or by Marko Apfel
Published on Fri, 25 Nov 2011 13:10:00 GMT Indexed on 2011/11/25 17:51 UTC
Read the original article Hit count: 400

Filed under:

Problem

this code does not work

Type t = typeof(ESRI.ArcGIS.Framework.AppRefClass);
System.Object obj = Activator.CreateInstance(t);

but yet this code

Type t = Type.GetTypeFromCLSID(typeof(ESRI.ArcGIS.Framework.AppRefClass).GUID);
System.Object obj = Activator.CreateInstance(t);

Reason

In the first variant the runtime tries to cast to AppRefClass . This is not possible.

And in the second one, the runtime does not knows anything about AppRefClass. So it leave it as IUnknown.

 

(originally communicated by my co-worker Ralf)

© Geeks with Blogs or respective owner