无法序列化对象

| 下面是我用来序列化对象的代码
College college = new College();
college= (College)(Session[\"XML\"]);

public void serializetoxml(College college)
{
    System.Xml.Serialization.XmlSerializer myserializer = new System.Xml.Serialization.XmlSerializer(college.GetType());
    // XmlSerializer myserializer = new XmlSerializer(typeof(College));
    TextWriter mywriter = new StreamWriter(\"C:\\\\invoice.xml\");
    myserializer.Serialize(mywriter, college);
    mywriter.Close();
} 
抱歉,我错过了为班级粘贴代码的地方,这是
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute(\"code\")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace=\"\")]           [System.Xml.Serialization.XmlRootAttribute]
public partial class College{

    /// <remarks/>
    public Header header;

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(\"Student\")]
    public Student Student;

    /// <remarks/>
    public Summary summary;
}

[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute(\"code\")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true,Namespace=\"\")] 
[System.Xml.Serialization.XmlRootAttribute]
public partial class Invoice {


    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(\"Activity\")]

    public List<Activity> Activity;

        }
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute(\"code\")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace=\"\")]
[System.Xml.Serialization.XmlRootAttribute(Namespace=\"\", IsNullable=false)]
public partial class Activity{

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(DataType = \"integer\")]
    public string StudentNumber;


    /// <remarks/>        
    public string mark1;

    ///  <remarks/> typed it in manually

    public string mark2;
   }
这是我得到的错误{\“存在反映类型\'A.Common.College \'的错误。\”} 这是一个实时类的例子。     
已邀请:
查看您所得到的内部异常。它将告诉您序列化哪个字段/属性。 您可以通过使用[XmlIgnore()]属性修饰字段/属性来将它们从xml序列化中排除。     

要回复问题请先登录注册