c# – 无法识别指定的类型
发布时间:2020-12-16 01:51:40 所属栏目:百科 来源:网络整理
导读:错误: {“The specified type was not recognized: name=’VitalsPlugin’, namespace=”,at .”} 码: public class SimpleSerializer{ static void Main() { string xml = "Plugin xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="V
错误:
码: 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 { } 解决方法
经过多次修补后,我遇到了一个x000:类型的
definition.在阅读定义后,我意识到这种类型指定了派生类.我将代码更新为
public class VitalsPlugin: Plugin { } 它的工作原理. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |