-1

this is my Serialize and Deserialize code

  public byte[] DTSerialize(object dt)
    {
        MemoryStream stream = new MemoryStream();
        System.Runtime.Serialization.IFormatter formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
        formatter.Serialize(stream, dt);
        return stream.GetBuffer();
    }


    public object DTDeserialize(byte[] buffer)
    {
        MemoryStream stream = new MemoryStream(buffer);
        System.Runtime.Serialization.IFormatter formatter = new BinaryFormatter();

        return formatter.Deserialize(stream) as object;
    }

and this call method code

        List<Series> ser = new List<Series>();
        foreach (Series item in chartControl1.Series)
        {
            ser.Add(item);
        }


byte[] btt = DTSerialize(ser);

but when i call code this exception throwing

An unhandled exception of type 'System.Runtime.Serialization.SerializationException' occurred in mscorlib.dll

Additional information: Type 'DevExpress.XtraCharts.Series' in Assembly 'DevExpress.XtraCharts.v14.1, Version=14.1.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a' is not marked as serializable.

lkmcelik
  • 77
  • 2
  • 10
  • can you use json as your serialization format? – oleksii Sep 14 '15 at 11:32
  • 1
    What is ser?? Is it 'DevExpress.XtraCharts.Series object?? – Akansha Sep 14 '15 at 11:33
  • no this is win application – lkmcelik Sep 14 '15 at 11:33
  • 2
    The error message is pretty clear. Not marked as Serializable means that the class you are trying to serialize (list of series) doesn't have a [Serializable] on it. You can easily search on google on how to serialize a list. edit: example http://stackoverflow.com/questions/5005900/how-to-serialize-listt – SpaceSteak Sep 14 '15 at 11:34
  • 1
    Hold on - the error clearly says " is not marked as serializable", so you won't be able to serialize it. EDIT - post one second after SpaceSteak (ie im not commenting on SpaceSteak's comment; I agree with him) – rbm Sep 14 '15 at 11:34
  • One more question - you are trying to serialize a UI component; but isn't it better to serialize whichever data you used to render the component (i.e. im assuming you did some binding of data to the control) – rbm Sep 14 '15 at 12:08

2 Answers2

3

You are trying to serialize object which is not market with [Serializable] attribute, i.e. it won't work.

rbm
  • 3,243
  • 2
  • 17
  • 28
  • One more question to the OP (already posted above): you are trying to serialize a UI component; but isn't it better to serialize whichever data you used to render the component (i.e. im assuming you did some binding of data to the control) – rbm Sep 14 '15 at 13:37
0

You can serialize the object from any assembly. Check the below link. It may help you.

How to serialize/deserialize an object loaded from another assembly?

Community
  • 1
  • 1
Akansha
  • 933
  • 7
  • 18