Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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();
        comReleaser.ManageLifetime(extensionManagerObject);
        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
add comment

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.