C# 如何将对象标记为可序列化

C# 如何将对象标记为可序列化,c#,wpf,serializable,documents,cloning,C#,Wpf,Serializable,Documents,Cloning,我有一个system.document.table对象,我想将该对象标记为可序列化,以便对其进行深度克隆。例外情况是,未将“System.Windows.Documents.Table”类型“in Assembly”PresentationFramework,版本=4.0.0.0,区域性=neutral,PublicKeyToken=31bf3856ad364e35”标记为可序列化。 FlowTable original = new FlowTable(); original = objF

我有一个system.document.table对象,我想将该对象标记为可序列化,以便对其进行深度克隆。例外情况是,未将“System.Windows.Documents.Table”类型“in Assembly”PresentationFramework,版本=4.0.0.0,区域性=neutral,PublicKeyToken=31bf3856ad364e35”标记为可序列化。

 FlowTable original =  new FlowTable();
 original = objFlowTab.deepclone();
其中objflowtab有一个表对象

[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);
        }
    }
}
[可序列化]
公共类流程表:表格
{ ....
....
公共静态类扩展方法
{
//深层克隆
公共静态T DeepClone(此T a)
{ 
使用(MemoryStream stream=new MemoryStream())
{
BinaryFormatter formatter=新的BinaryFormatter();
序列化(流,a);
流位置=0;
返回(T)格式化程序。反序列化(流);
}
}
}

格式化程序中出现错误。序列化(流,a);

向要序列化的类添加
[Serializable]
属性


请参阅有关C#序列化的详细信息

有关序列化对象,您必须在类定义中包含
[serializable]

[Serializable]
public class YourClass
{
  //Your definition here;
}

除了错误消息之外,请显示一些代码。这应该通过先搜索您自己来快速找到。看起来您从未搜索过任何内容?的可能副本请确保您的对象没有任何无法序列化的成员(例如,某些类型也没有标记
Serializable
)。在某些情况下,您需要显式实现接口
ISerializable
。这个主意不好。将表序列化为XAML。我怀疑二进制序列化在这里是否有效。