错误:
{“无法识别指定的类型:name ='VitalsPlugin', namespace ='',at。“}
代码:
public class SimpleSerializer
{
static void Main()
{
string xml = "<Plugin xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"VitalsPlugin\" ID=\"eaded5f3-7019-47b9-8f9f-e7c1879774f4\"><CopyForwardChecked>true</CopyForwardChecked></Plugin>";
StringReader reader = new StringReader(xml);
var result = Deserialize(reader);
}
static Plugin Deserialize(TextReader xml)
{
XmlSerializer xsr = new XmlSerializer(typeof(Plugin), new Type[] {typeof(VitalsPlugin)});
Plugin result = xsr.Deserialize(xml) as Plugin;
return result;
}
}
其他有用的代码:
[XmlInclude(typeof(VitalsPlugin))]
public class Plugin
{
}
public class VitalsPlugin
{
}
答案 0 :(得分:7)
经过多次修补后,我遇到了xsi:type
public class VitalsPlugin: Plugin
{
}
。在阅读定义后,我意识到这种类型指定了派生类。我将代码更新为
{{1}}
它有效。