我有一个基类,其中有一个带有XmlText属性的Name属性。
当序列化继承类时,我会收到一个异常:
反射 '[type name]' 类型时发生错误。---> System.InvalidOperationException: 无法序列化类型为 '[type name]' 的对象。基类型 '[base type name]' 具有 simpleContent,只能通过添加 XmlAttribute 元素来扩展。请考虑将基类的 XmlText 成员更改为字符串数组。
这是我的类定义,在序列化为xml时出现了错误。
[Serializable]
public class LookupItem
{
[System.Xml.Serialization.XmlAttribute()]
public int ID { get; set; }
[System.Xml.Serialization.XmlText()]
public string Name { get; set; }
}
[Serializable]
public class Vendor : LookupItem
{
public string ContactNumber { get; set; }
}
[Serializable]
public class Vendors : List<Vendor>
{
}