使用 xsi:type 反序列化 xml 会导致类型无法识别错误我的类定义中缺少什么?

问题描述

反序列化此 XML 会导致以下错误

<bevestigingDu01 xmlns="http://register.geostandaarden.nl/xmlschema/geobag/1.1" 
                 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
                 xmlns:BG="http://www.egem.nl/StUF/sector/bg/0310">
   <BG:standplaats>
      <BG:identificatie xsi:type="BG:ObjectNummering-geoBAG">0441030010013666</BG:identificatie>
    </BG:standplaats>
</bevestigingDu01>

system.invalidOperationException: The specified type is not recognized: name=ObjectNummering-geoBAG,namespace=http://www.egem.nl/StUF/sector/bg/0310,at <identificatie xmlns='http://www.egem.nl/StUF/sector/bg/0310'>.
   at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderBevestigingDu01.Read59_ObjectNummeringe(Boolean isNullable,Boolean checkType)
   at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderBevestigingDu01.Read79_BevestigingDu01Standplaats(Boolean isNullable,Boolean checkType)
   at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderBevestigingDu01.Read85_BevestigingDu01(Boolean isNullable,Boolean checkType)
   at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderBevestigingDu01.Read86_bevestigingDu01()

类定义如下(这里只介绍主要结构):

[XmlTypeAttribute(TypeName="ObjectNummering-e",Namespace="http://www.egem.nl/StUF/sector/bg/0310")]
[XmlIncludeAttribute(typeof(ObjectNummeringgeoBAG))]
public partial class ObjectNummeringe
{
...
}
[XmlTypeAttribute(TypeName="ObjectNummering-geoBAG",Namespace="http://www.egem.nl/StUF/sector/bg/0310")]
public partial class ObjectNummeringgeoBAG : ObjectNummeringe
{}

[XmlTypeAttribute(TypeName="STA-geoBAG-identificatie",Namespace="http://www.egem.nl/StUF/sector/bg/0310")]
public partial class STAgeoBAGidentificatie
{
   #region Private fields
   private ObjectNummeringe _identificatie;
   #endregion
        
  
   [XmlElement(IsNullable=true,Order=0)]
   public ObjectNummeringe identificatie
   {
    get {return _identificatie;}
    set {_identificatie = value;}
   }
}

[XmlTypeAttribute(AnonymousType=true,Namespace="http://www.egem.nl/StUF/sector/bg/0310")]
public partial class BevestigingDu01Standplaats : STAgeoBAGidentificatie
{
...
}

[XmlTypeAttribute(Namespace="http://www.egem.nl/StUF/sector/bg/0310")]
[XmlRootAttribute("bevestigingDu01",Namespace="http://register.geostandaarden.nl/xmlschema/geobag/1.1",IsNullable=false)]
public partial class BevestigingDu01
{
   ...
   [XmlElement("standplaats",typeof(BevestigingDu01Standplaats),Order=2)]
   ...
}

据我所知,这是正确的: ObjectNummeringgeoBAG 派生自 ObjectNummeringe。

ObjectNummeringgeoBAG 包含在 ObjectNummeringe 中。

它们也在同一个命名空间中。

我错过了什么?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)