I'm storing a reference to an IMap in a custom object (which is stored by a custom extension) so that it can listen to map events. When I save the custom object using IPersistStream and then reload the MXD, it appears that I now have a reference to a COPY of the original IMap. I tested this by making a simple custom extension that saves the first IMap in the document... when reopening the saved MXD, the saved IMap != the first IMap in the document.

Is this how it should be working? Should I just be saving the location of the map in the document (rather than the actual IMap) and then resetting the reference during IPeristStream.Load?

I'm using C#, ArcGIS 10.0, and VS 2008.

  • What makes you think serializing and deserializing an object would give you the same object back? It will only ever be a copy of the original object. Given that, is that a problem for you, and if it is, how so? Also why does the map need to be persisted with the object? Why does an object that listens to events need to be persisted? Why can't you have one object specifically designed for the data that needs to be persisted, and other code to deal with events and references to other parts of the running ArcGIS app? What exactly is the purpose of the customizations? Can you share your code? – blah238 Apr 25 '13 at 22:14
  • I suppose the point of all this is that something in the application needs to know which map to listen to when the MXD is opened again because data in my application is altered when layers are added and removed. If the answer is to simply store the location of the map rather than the map itself, that's fine. I was under the impression (based on something from the ESRI forums) that persisting something that was already persisted by the MXD itself would hold a reference to the same object that the MXD is storing. It sounds like that is incorrect. – kylercashman Apr 25 '13 at 22:24
  • I have not heard that so if you could cite it that would be great. I would expect that they would be two different object references. I agree that it makes more sense to store either the name or index of the map (data frame) than its entirety, or just make the assumption that it's always the first map in the MXD. – blah238 Apr 25 '13 at 22:29
  • Ugh... I just did a quick search and I think I found what I had read. Reading it more closely, it was referring to the same object stored twice in a PropertySet referencing the same object vs different copies. Completely irrelevant to me. – kylercashman Apr 25 '13 at 22:36
  • 1
    If you store two references to a single object in an ObjectStream, it will resolve itself on load as one object. In your case, you are persisting to a separate stream outside the MXD so this will not work. – Craig Williams Apr 27 '13 at 1:03

I finally got back to this project and ended up storing the map index rather than the map itself. Works great. Thanks for the help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.