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