Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to mark an object as Serializable

I have a system.document.table object and i want to mark that object as Serializable for deep cloning it. the exception is Type 'System.Windows.Documents.Table' in Assembly 'PresentationFramework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' is not marked as serializable.

 FlowTable original =  new FlowTable();
 original = objFlowTab.deepclone();

where objflowtab is having a table object

[Serializable]
public class FlowTable : Table
{ ....
  ....
  public static class ExtensionMethods
{
    // Deep clone
    public static T DeepClone<T>(this T a)
    { 

        using (MemoryStream stream = new MemoryStream())
        {

            BinaryFormatter formatter = new BinaryFormatter();
            formatter.Serialize(stream,a);
            stream.Position = 0;
            return (T)formatter.Deserialize(stream);
        }
    }
}

i am getting error in formatter.Serialize(stream,a);

like image 790
jeevan_jk Avatar asked Oct 26 '25 11:10

jeevan_jk


1 Answers

Add a [Serializable] attribute to the class being serialized.

See details about C# serialization here

like image 129
Shedal Avatar answered Oct 28 '25 03:10

Shedal