protected override void OnSave(Stream outStrm) { base.OnSave(outStrm); //PersistenceHelper.Save<SerializableObserveableCollection<ESRI.ArcGIS.Carto.ILayer>>(outStrm, availableLayer); var bf = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); //bf.Serialize(outStrm, availableLayer); PersistenceHelper.Save<ObservableCollection<Layer>>(outStrm, availableLayer); } protected override void OnLoad(Stream inStrm) { base.OnLoad(inStrm); //SerializableObserveableCollection<ESRI.ArcGIS.Carto.ILayer> o = new SerializableObserveableCollection<ESRI.ArcGIS.Carto.ILayer>(); var bf = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); availableLayer = new ObservableCollection<Layer>(); //availableLayer = (ObservableCollection <Layer>) bf.Deserialize(inStrm); PersistenceHelper.Load<ObservableCollection<Layer>>(inStrm, ref availableLayer); }
Solved! Go to Solution.
In my Add-in, I used the following code. I've serialized a dictionary in the OnSave subProtected Overrides Sub OnLoad(ByVal inStrm As System.IO.Stream) 'MyBase.OnLoad(inStrm) Dim binaryFormatter = New System.Runtime.Serialization.Formatters.Binary.BinaryFormatter() Try theDict = CType(binaryFormatter.Deserialize(inStrm), Dictionary(Of Object, Object)) If theDict.Count > 0 Then CreateRenderer() Catch ex As Exception System.Windows.Forms.MessageBox.Show(ex.ToString, "Extension: OnLoad") End Try End Sub
sealed class MCDADeserializationBinder : SerializationBinder { public override Type BindToType(string assemblyName, string typeName) { return Type.GetType(typeName + "," + Assembly.GetExecutingAssembly().FullName); } }
protected override void OnSave(Stream outStrm) { var bf = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); //persist onlz the unique layer names of selected layer _listOfSelectedUniqueLayerNamesForPersistence = _listOfAvailableLayer.Where(l => l.isSelected).Select(l => l.UniqueLayerName).ToList(); bf.Serialize(outStrm, _listOfSelectedUniqueLayerNamesForPersistence); } protected override void OnLoad(Stream inStrm) { var bf = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); //bf.AssemblyFormat = System.Runtime.Serialization.Formatters.FormatterAssemblyStyle.Simple; bf.Binder = new MCDADeserializationBinder(); _listOfSelectedUniqueLayerNamesForPersistence = null; _listOfSelectedUniqueLayerNamesForPersistence = bf.Deserialize(inStrm) as List<string>; }
Protected Overrides Sub OnLoad(ByVal inStrm As System.IO.Stream) 'MyBase.OnLoad(inStrm) Dim binaryFormatter = New System.Runtime.Serialization.Formatters.Binary.BinaryFormatter() Try theDict = CType(binaryFormatter.Deserialize(inStrm), Dictionary(Of Object, Object)) If theDict.Count > 0 Then CreateRenderer() Catch ex As Exception System.Windows.Forms.MessageBox.Show(ex.ToString, "Extension: OnLoad") End Try End Sub
In my Add-in, I used the following code. I've serialized a dictionary in the OnSave subProtected Overrides Sub OnLoad(ByVal inStrm As System.IO.Stream) 'MyBase.OnLoad(inStrm) Dim binaryFormatter = New System.Runtime.Serialization.Formatters.Binary.BinaryFormatter() Try theDict = CType(binaryFormatter.Deserialize(inStrm), Dictionary(Of Object, Object)) If theDict.Count > 0 Then CreateRenderer() Catch ex As Exception System.Windows.Forms.MessageBox.Show(ex.ToString, "Extension: OnLoad") End Try End Sub
sealed class MCDADeserializationBinder : SerializationBinder { public override Type BindToType(string assemblyName, string typeName) { return Type.GetType(typeName + "," + Assembly.GetExecutingAssembly().FullName); } }
protected override void OnSave(Stream outStrm) { var bf = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); //persist onlz the unique layer names of selected layer _listOfSelectedUniqueLayerNamesForPersistence = _listOfAvailableLayer.Where(l => l.isSelected).Select(l => l.UniqueLayerName).ToList(); bf.Serialize(outStrm, _listOfSelectedUniqueLayerNamesForPersistence); } protected override void OnLoad(Stream inStrm) { var bf = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); //bf.AssemblyFormat = System.Runtime.Serialization.Formatters.FormatterAssemblyStyle.Simple; bf.Binder = new MCDADeserializationBinder(); _listOfSelectedUniqueLayerNamesForPersistence = null; _listOfSelectedUniqueLayerNamesForPersistence = bf.Deserialize(inStrm) as List<string>; }