在进行xml序列化时,正常单个类可以正常序列化,当遇到派生类时,就会报错The type xx' was not expected.Use the XmlInclude or SoapInclude attribute to specify types that are not known statically.如下图情况:
当我们使用MessageResponseHeader时就会报上述错误,
第一种方法是在基类添加XmlInclude特性
第二种方法就是在XmlSerializer的构造函数内指定派生类型
var xs =new XmlSerializer(typeof(MessageResponseHeader), new Type[] {typeof(MessageHeader) });