Select to view content in your preferred language

IPersistVariant::Load not called

1078
4
Jump to solution
07-17-2012 05:30 AM
by Anonymous User
Not applicable
Hi,

I have migrated my ArcMap-extension from COM to an add-in. Since then I am having trouble to persist my custom layer to the mxd-document. When I save to a document the IPersistVariant::Save method is called normally, but when I open that document the Load method is not called. Ultimately I added a very simple ILayer implementation to test if the problem was somewhere else in my class, but with this simple test the exact same problem occurs: the save method is called but not the load method.

Does anybody have an idea what could be wrong or a suggesting how to investigate further? Because I am at a dead end here...

This is my test class:

Imports System.Runtime.InteropServices Imports ESRI.ArcGIS.Carto Imports ESRI.ArcGIS.esriSystem Imports ESRI.ArcGIS.Geometry Imports ESRI.ArcGIS.Display  <Guid("E9CB507B-9A23-4272-B4E6-65AE059DEBD4"), ComVisible(True), ClassInterface(ClassInterfaceType.None), ProgId("AnchorPP.TestLayer")> Public Class TestLayer : Implements ILayer, IPersistVariant      Private m_point As IPoint = Nothing     Private m_UID As UID      Public Sub New()         MyBase.New()         m_point = New PointClass()      End Sub      Public ReadOnly Property AreaOfInterest As ESRI.ArcGIS.Geometry.IEnvelope Implements ESRI.ArcGIS.Carto.ILayer.AreaOfInterest         Get          End Get     End Property      Public Property Cached As Boolean Implements ESRI.ArcGIS.Carto.ILayer.Cached         Get             Return False         End Get         Set(ByVal value As Boolean)          End Set     End Property      Public Sub Draw(ByVal DrawPhase As ESRI.ArcGIS.esriSystem.esriDrawPhase, ByVal Display As ESRI.ArcGIS.Display.IDisplay, ByVal TrackCancel As ESRI.ArcGIS.esriSystem.ITrackCancel) Implements ESRI.ArcGIS.Carto.ILayer.Draw          m_point.X = My.Document.ActiveView.Extent.XMin + My.Document.ActiveView.Extent.Width \ 2         m_point.Y = My.Document.ActiveView.Extent.YMin + My.Document.ActiveView.Extent.Height \ 2          Dim simplepointsymbol As New SimpleMarkerSymbol         Dim red As New RgbColor         red.Red = 255          simplepointsymbol.Color = red         simplepointsymbol.Size = 5         simplepointsymbol.Style = esriSimpleMarkerStyle.esriSMSCircle          Display.SetSymbol(simplepointsymbol)         Display.DrawPoint(m_point)      End Sub      Public Property MaximumScale As Double Implements ESRI.ArcGIS.Carto.ILayer.MaximumScale         Get          End Get         Set(ByVal value As Double)          End Set     End Property      Public Property MinimumScale As Double Implements ESRI.ArcGIS.Carto.ILayer.MinimumScale         Get          End Get         Set(ByVal value As Double)          End Set     End Property      Public Property Name As String Implements ESRI.ArcGIS.Carto.ILayer.Name         Get             Return "TestLayer"         End Get         Set(ByVal value As String)          End Set     End Property      Public Property ShowTips As Boolean Implements ESRI.ArcGIS.Carto.ILayer.ShowTips         Get          End Get         Set(ByVal value As Boolean)          End Set     End Property      Public WriteOnly Property SpatialReference As ESRI.ArcGIS.Geometry.ISpatialReference Implements ESRI.ArcGIS.Carto.ILayer.SpatialReference         Set(ByVal value As ESRI.ArcGIS.Geometry.ISpatialReference)          End Set     End Property      Public ReadOnly Property SupportedDrawPhases As Integer Implements ESRI.ArcGIS.Carto.ILayer.SupportedDrawPhases         Get             Return CInt(esriDrawPhase.esriDPGeography)         End Get     End Property      Public ReadOnly Property TipText(ByVal x As Double, ByVal y As Double, ByVal Tolerance As Double) As String Implements ESRI.ArcGIS.Carto.ILayer.TipText         Get          End Get     End Property      Public ReadOnly Property Valid As Boolean Implements ESRI.ArcGIS.Carto.ILayer.Valid         Get             Return True         End Get     End Property      Public Property Visible As Boolean Implements ESRI.ArcGIS.Carto.ILayer.Visible         Get             Return True         End Get         Set(ByVal value As Boolean)          End Set     End Property      Public ReadOnly Property ID As ESRI.ArcGIS.esriSystem.UID Implements ESRI.ArcGIS.esriSystem.IPersistVariant.ID         Get             m_UID = New UID             m_UID.Value = "{" & Me.GetType.GUID.ToString & "}"             Return m_UID         End Get     End Property      Public Sub Load(ByVal Stream As ESRI.ArcGIS.esriSystem.IVariantStream) Implements ESRI.ArcGIS.esriSystem.IPersistVariant.Load          Dim value = Stream.Read      End Sub      Public Sub Save(ByVal Stream As ESRI.ArcGIS.esriSystem.IVariantStream) Implements ESRI.ArcGIS.esriSystem.IPersistVariant.Save          Stream.Write("some value")      End Sub End Class
0 Kudos
1 Solution

Accepted Solutions
AlexanderGray
Honored Contributor
Do you have a specific reason to migrate from a com component model to an add-in?  The documentation does not list an ILayer as a component type you can create with an add-in.  Add-ins are fairly limited in possibilities.

http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#//0001000000w2000000

View solution in original post

0 Kudos
4 Replies
AlexanderGray
Honored Contributor
Do you have a specific reason to migrate from a com component model to an add-in?  The documentation does not list an ILayer as a component type you can create with an add-in.  Add-ins are fairly limited in possibilities.

http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#//0001000000w2000000
0 Kudos
by Anonymous User
Not applicable
Yes, my client requires the migration because of the deployment benefits.
I think you are right that the add-in is the problem. Custom layers are no problem but it is the implementation of the IPersistVariant interface that is not supported i think. Through a guid the ID of the class that is persisted in the document is known to ArcMap. I guess this ID has to be registered like this is done with the classic COM approach. But of course an add-in is not registered...
I will look into the persistance that is available with the add-in extension, through the Open en Save methods.
0 Kudos
by Anonymous User
Not applicable
The classic method of persisting a custom layer in the document by implementing IPersistVariant or IPersistStream cannot be used with the add-in approach. I ended up persisting the necessary properties of the ILayer implementation through the Load and Save methods on the Extension object. And then in the Load event I instantiate an object of my custom layer, assign the properties manually and then add the custom layer object to the map manually via IMap::AddLayer().
Not very elegant, but it works.
0 Kudos
liuyang1
Emerging Contributor
I got the same problem,I want to save the google map in my mxd,so I write a custom layer ,after saved ,I open the mxd file,but these is nothing about my custom layer info ,do you  have any good ideas for my problem?
Thanks!
0 Kudos