Thursday, August 5, 2010

Finding your custom ArcGIS extension with C#

An extension object is handy and logical place to store data when creating a custom component for ArcGIS. However, you need to be able access the extension object from your other objects such as commands. Here's how to do it.

Put something like this in the command's OnCreate() method (not in the constructor, especially if you're using a just-in-time extension, because the extension may not be loaded yet when the command is constructed):

UID uid = new UIDClass();
uid.Value = "MyNamespace.MyJITExtension";
m_extension = (MyJITExtension)m_application.FindExtensionByCLSID(uid);

The above method worked fine for me with ArcGIS 9.3 and Visual Studio 2008. I came across the following error when using ArcGIS 10 and Visual Studio 2010:

Error 4: Interop type 'ESRI.ArcGIS.esriSystem.UIDClass' cannot be embedded. Use the applicable interface instead.

To solve this problem, change the Embed Interop Types property for each referenced ESRI assembly to False. Or don't target .NET Framework 4.0.

1 comment:

  1. Thanks A LOT!!! Was trying to build an ArcGIS engine application and this helped me out. God bless!