【 以下文字转载自 DotNET 讨论区 】
发信人: Encryption (ANewLife), 信区: DotNET
标 题: 问一个XML序列化的问题
发信站: BBS 水木清华站 (Sun Jun 6 20:49:51 2004), 站内
有如下两个类:
public class A{
public ArrayList list;
public A(){
list = new ArrayList();
}
public void XMLSerialize(string filename){
StreamWriter sw = new StreamWriter(filename,false,System.Text.Encoding.Default,1024);
XmlSerializer serializer = new XmlSerializer(typeof(A));
serializer.Serialize(sw,this);
sw.Close();
}
}
public class B{
public string value;
}
在A的list里放了一些B类的对象,将A序列化时出错说:
Unhandled Exception: System.InvalidOperationException: There was an error genera
ting the XML document. ---> System.InvalidOperationException: The type FinalBatt
le.MapItem was not expected. Use the XmlInclude or SoapInclude attribute to spec
ify types that are not known statically.
在A的序列化方法上添加了[XmlIncludeAttribute(typeof(B))]还是不行,请问应该怎么修改?.net新手上路,请大侠指教!
--
修改:Encryption FROM 166.111.68.*
FROM 166.111.68.*