无法序列化对象
|
下面是我用来序列化对象的代码
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 \'的错误。\”}
这是一个实时类的例子。
没有找到相关结果
已邀请:
1 个回复
翁茄口霉氖