|     Documentation    |     Premium Support

How to save and load map state in version 12?

I am attempting to save and load all the settings, overlays, layers, etc on a MapView, and attempted to use the SaveState() method. However, that generates the following Exception:

System.Runtime.Serialization.SerializationException: Type ‘System.RuntimeType’ in Assembly ‘System.Private.CoreLib, Version=, Culture=neutral, PublicKeyToken=7cec85d7bea7798e’ is not marked as serializable.
at System.Runtime.Serialization.FormatterServices.InternalGetSerializableMembers(Type type)
at System.Runtime.Serialization.FormatterServices.<>c.b__5_0(MemberHolder mh)
at System.Collections.Concurrent.ConcurrentDictionary2.GetOrAdd(TKey key, Func2 valueFactory)
at System.Runtime.Serialization.FormatterServices.GetSerializableMembers(Type type, StreamingContext context)
at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitMemberInfo()
at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitSerialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter, SerializationBinder binder)
at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Write(WriteObjectInfo objectInfo, NameInfo memberNameInfo, NameInfo typeNameInfo)
at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Serialize(Object graph, BinaryFormatterWriter serWriter, Boolean fCheck)
at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph, Boolean check)
at ThinkGeo.Core.MapViewBase.SaveStateCore()
at ThinkGeo.Core.MapViewBase.SaveState()

I tried using the GeoSerializer object to serialize the MapView control specified in this thread: Map Suite SaveState and LoadState but that does not save the entire state of the mapView. In fact, it seems to only save an empty map with no properties, collections, etc.

I thought perhaps it has something to do with the GeoSerializationFormatter class, but that appears to be abstract only and the documentation doesn’t indicate there are any concrete classes based upon this class…

So how does one now correctly save the state of a MapView control and then reload it at a later time?

Hi Travis,

I tried to call SaveState() method of an empty map, it worked. I think the exception was caused by some specific fields of some layers. Could you send us a sample? so we can figure out which fields might cause this and fix it then.