【问题标题】:The specified type was not recognized指定的类型未被识别
【发布时间】:2012-12-04 16:27:48
【问题描述】:

错误:

{"指定类型未被识别:name='VitalsPlugin', 命名空间='',在。"}

代码:

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
{
}

【问题讨论】:

    标签: c# xml serialization xml-serialization


    【解决方案1】:

    经过多次修改,我遇到了 definitionxsi:type。阅读定义后,我意识到这种类型指定了一个派生类。我将代码更新为

    public class VitalsPlugin: Plugin
    {
    }
    

    它有效。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-28
      • 2022-06-14
      • 2021-10-19
      • 1970-01-01
      • 2018-09-09
      • 1970-01-01
      相关资源
      最近更新 更多