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

I created a custom extension in ArcMap 10.1 which implements the IPersistVariant interface. State related to the extension features is persisted and retrieved via the Load and Save methods. Everything works fine in ArcMap.

I am now building an ArcEngine app which needs to load documents which have been modified with the custom extension in ArcMap. I need to be able to load in the extension, so that when I load the document, the extension specific state is retrieved. I have no problem loading the extension in ArcEngine as follows:

        Type extensionManagerType = Type.GetTypeFromProgID("esriSystem.ExtensionManager");
        System.Object extensionManagerObject = Activator.CreateInstance(extensionManagerType);
        this.comReleaser = new ComReleaser();
        this.extensionManager = extensionManagerObject as IExtensionManager;
        IExtensionManagerAdmin extensionManagerAdmin = this.extensionManager as IExtensionManagerAdmin;

        // Add the PirsaExtension to the extension manager to load it.
        UID uID = new UIDClass();
        uID.Value = "PirsaX.Extension.PirsaToolsExtension";
        extensionManagerAdmin.AddExtension(uID, this as IBatchApplication);
        IExtension extension = this.extensionManager.FindExtension("PirsaMappingToolsExtension");
        // Remember the extension manager as a PirsaExtension so that later we can use it to load
        // a document.
        PirsaToolsExtension pirsaExtension = extension as PirsaToolsExtension;
        this.batchMapGenerator = pirsaExtension.BatchMapGenerator;
        // Enable the extension.
        IExtensionConfig extensionConfig = extension as IExtensionConfig;
        extensionConfig.State = esriExtensionState.esriESEnabled;

Doing this loads the extension properly. In the debugger I see its Startup method being called and see the extension being enabled.

The problem arises when I open the document. The extension's Load(IVariantStream stream) method never gets called. Here is how I open the document.

        mapDocument = new MapDocumentClass();
                if (mapDocument.get_IsMapDocument(filePath))
                    mapDocument.Open(filePath, String.Empty);

There is a pause when the mapDocument loads, and then I can access its details, but none of the custom state is there. How do I tie opening the document into the extension?

Any advice or insights would be greatly appreciated.

Tom Cuthill

share|improve this question

Your Answer


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

Browse other questions tagged or ask your own question.