0
下面是我使用的序列化對象無法序列化一個對象
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'的錯誤。」}
這是一個realtimeclass的例子。
問題是什麼?你的標題說無法序列化..你的錯誤是什麼? – 2011-04-15 00:52:20
你能提供一些關於「無法序列化」的細節嗎?如果你可以發佈'College'類的代碼,它也會有所幫助。 – 2011-04-15 00:52:47
是的,你是對的。那是你的代碼。有什麼問題?你有任何錯誤? – 2011-04-15 00:53:35