3

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);

jeevan_jk
  • 111
  • 2
  • 13
  • 2
    Please show some code in addition to the error message. – Codor Sep 29 '15 at 10:57
  • this should have been found out quickly by searching yourself first. Looks like you have never searched for anything? – Hopeless Sep 29 '15 at 10:59
  • possible duplicate of [Error - is not marked as serializable](http://stackoverflow.com/questions/15707872/error-is-not-marked-as-serializable) – Volkan Paksoy Sep 29 '15 at 10:59
  • be sure that your object does not have any members which cannot be serialized (such as of some type which also does not have `Serializable` marked). In some cases you need to implement the interface `ISerializable` explicitly. – Hopeless Sep 29 '15 at 11:01
  • Bad idea. Serialize table to XAML. I doubt, that binary serialization will work here. – Dennis Sep 29 '15 at 11:20

2 Answers2

9

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

See details about C# serialization here

sujith karivelil
  • 28,671
  • 6
  • 55
  • 88
Shedal
  • 181
  • 3
2

For serializable objects you have to include [Serializable] with your class definition

[Serializable]
public class YourClass
{
  //Your definition here;
}
sujith karivelil
  • 28,671
  • 6
  • 55
  • 88