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 have an ArcMap extension in which I'm trying to persist a string value. When the document is saved, the public member m_LayerName in the application extension class is not being persisted. Either it's not being written to the stream or it's not being loaded correctly once the document is reopened. I'm not sure what I'm doing wrong. The Save and Load events are definitely being executed appropriately, but no data is being saved. This is my first attempt at persisting data with an extension so I'm missing something. Below is the relevant code.

Public m_LayerName As String

...

Public ReadOnly Property ID() As ESRI.ArcGIS.esriSystem.UID Implements ESRI.ArcGIS.esriSystem.IPersistVariant.ID
    Get
        Dim typeID As UID = New UIDClass()
        typeID.Value = Me.GetType().GUID.ToString("B")
        Return typeID
    End Get
End Property

Public Sub Load(ByVal Stream As ESRI.ArcGIS.esriSystem.IVariantStream) Implements ESRI.ArcGIS.esriSystem.IPersistVariant.Load
    m_LayerName = CStr(Stream.Read())
    Marshal.ReleaseComObject(Stream)
End Sub

Public Sub Save(ByVal Stream As ESRI.ArcGIS.esriSystem.IVariantStream) Implements ESRI.ArcGIS.esriSystem.IPersistVariant.Save
    Stream.Write(m_LayerName)
    Marshal.ReleaseComObject(Stream)
End Sub
share|improve this question
1  
Is this a classic COM IExtension implementation or an add-in? Add-ins have a different persistence pattern, where IPersistStream or IPersistVariant are not used. –  Petr Krebs Jan 25 '11 at 21:09
add comment

1 Answer

Try it without calling releasecomobject on the stream, I think the app still needs to use the stream.

BTW, also I'd recommend adding a version property, it sure is a pain when you update an extension and there are mxds you're being asked to be backward compatible with.

share|improve this answer
    
I am quite intrigued.. not sure, but I do not believe this is the issue. ReleaseComObject and FinalReleaseComObject only affect the reference count managed by the CLR. When the CLR holds a reference to a COM object (creates its RCW), it calls IUnknown.AddRef exactly once, manages a reference count of its own, and as soon as it drops to 0, calls IUnknown.Release. When ArcMap is performing the serialization, it holds onto the stream object as well, and as such, releasing the CLR's single reference should not have any negative side effects. –  Petr Krebs Jan 24 '11 at 23:54
    
And also (knowing one can never fully believe those samples), in some samples ESRI explicitly guides you to release the stream object, e.g. this article: resources.esri.com/help/9.3/ArcGISEngine/dotnet/… –  Petr Krebs Jan 24 '11 at 23:56
    
@petr - I'm not for certain releasecomobject on the stream can cause problems, just that I never do that, and have never had a problem with any of persistable extensions I've written. Another possible explanation might be a guid collision, perhaps as a result of copying and pasting code from another IExtension class without changing the guid. –  Kirk Kuykendall Jan 25 '11 at 2:49
    
I tried it without the ReleaseCom to no avail. It seems like the data is simply not being written to the stream, like it's not associating it with the GUID. –  Jeff Berry Jan 25 '11 at 16:12
    
This is a new extension, so there shouldn't be any duplicate GUID. I'll try a test new test project though to see what happens. –  Jeff Berry Jan 25 '11 at 16:15
show 3 more comments

Your Answer

 
discard

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

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