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.

2 comments:

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

    ReplyDelete
  2. Mystino Casino - Free Play in Demo Mode - Casino In Japan
    Mystino Casino online slot game has a great RTP and an 다파벳 excellent sign-up fun88 soikeotot bonus ミスティーノ that will increase your chances of winning. The game is

    ReplyDelete