Serialization Error

Topics: Windows Forms
Dec 4, 2011 at 1:33 PM

Hello

First of all Thanks for great control.

 

i have issues about serializing the overlays, i try SerializeOverlays with no luck, saying that Pen is not marked as Serializable.

also try to modify the code not saving the Pen and Brush Property but after that another error occur ( The constructor to deserialize an object of type 'GMap.NET.WindowsForms.Markers.GMarkerGoogle' was not found. )

 

am i doing smth wrong?

 

the code is:

public T DeepClone<T>(T obj)       

{           

using (var ms = new System.IO.MemoryStream())           

{               

var formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();               

formatter.Serialize(ms, obj);

ms.Position = 0;

return (T)formatter.Deserialize(ms);           

}       

}

 

usage:

GMapOverlay overlay = DeepClone<GMapOverlay>(<some overlay>);

 

Coordinator
Dec 4, 2011 at 2:43 PM

i've never used serialization, don't know

Coordinator
Dec 4, 2011 at 4:08 PM

p.s. found the problem, default markers wasn't implemented correctly:

"If you inherit from a class which is implementing ISerializable (like Hashtable) and you want that your class to be serializable also, you must implement the methods from ISerializable interface:

- the serialization constructor, used at deserialization; which is a must; because you didn't implement it you have that error

protected CSDictionary(SerializationInfo info, StreamingContext context) : base(info, context) { }

- the serialization method GetObjectData used at serialization, which you need to implement if you have additional data to serialize."

Coordinator
Dec 4, 2011 at 8:24 PM

check it now, should be ok

Dec 5, 2011 at 2:43 PM

Hi,

 

Thanks for detailed explanation.

still has errors on Pen in GMapPolygon, anyway decide to impement my own class which collect data i need and be serialized.

 

Best Regards.

Coordinator
Dec 5, 2011 at 4:49 PM

fixed now ;}

Dec 5, 2011 at 6:59 PM

THANKS