【发布时间】:2016-05-14 08:48:56
【问题描述】:
我使用的数据源总是通过相同的父类(xml 中的模型)发送数据,并使用 xsi:type 来确定类的实际类型。在他们开始向 xsi:type 添加命名空间之前,这一直运行良好。现在无论我尝试什么,它都不会反序列化。
这是 XML:
<ModelResource xmlns:ot="http://www.example.com/otSpace">
<Models xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance xsi:type="ot:myChildClass">
Stuff here
</Models>
</ModelResource>
根节点
[XmlRoot("ModelResource")]
public class XmlRoot
{
[XmlElement("Models")]
public List<BaseObject> Bases { get; set; }
}
父类
[XmlInclude(typeof(MyChildClass))]
public abstract class BaseObject
{
}
子类
[XmlType(TypeName = "myChildClass", Namespace = "http://www.example.com/otSpace")]
public class MyChildClass : BaseObject
{
}
当我反序列化这个 XML 时,我得到了错误:
{"指定类型未被识别:name='myChildClass', namespace='http://www.example.com/otSpace', at ."}
感谢您的帮助。
【问题讨论】: