.NET XML序列化错误(有一个错误的反射式) [英] .NET XML Serialization error (There was an error reflecting type)

查看:324
本文介绍了.NET XML序列化错误(有一个错误的反射式)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是的,我知道非常通用的冠军,但我现在要解释的。



下面给出的类定义,有人可以解释为什么我会得到这个异常当调用序列化()方法。



{有反射式'FNM.MISMO_3_0.FOREIGN_OBJECT'。一个错误}



{选择标识符类型ItemsElementName是类型'项目'的不一致。请使用System.Collections.Generic.List`1数组[MISMO_3_0.ItemsChoiceType,MISMO_3_0,版本为1.0。 0.0,文化=中立,公钥=空]。}



感谢您,
斯蒂芬

  [System.CodeDom.Compiler.GeneratedCodeAttribute(的System.Xml,4.0.30319.225)] 
[System.SerializableAttribute()]
[系统.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute(准则)]
[System.Xml.Serialization.XmlTypeAttribute(命名空间=http://www.mismo.org/residential / 2009 /模式)]
[System.Xml.Serialization.XmlRootAttribute(命名空间=http://www.mismo.org/residential/2009/schemas,ISNULLABLE = TRUE)]
公部分类FOREIGN_OBJECT
{

私人列表<对象> itemsField;

私人列表< ItemsChoiceType> itemsElementNameField;

私人MISMOresourceLink TYPEFIELD;

私人布尔typeFieldSpecified;

私人字符串roleField;

私人字符串titleField;

私人字符串的labelField;

私人字符串sequenceNumberField;

私有静态System.Xml.Serialization.XmlSerializer串;

公共FOREIGN_OBJECT()
{
this.itemsElementNameField =新的List< ItemsChoiceType>();
this.itemsField =新的List<对象>();
}

[System.Xml.Serialization.XmlElementAttribute(CharacterEncodingSetType的typeof(CharacterEncodingSetEnum),令= 0)
[System.Xml.Serialization.XmlElementAttribute( CharacterEncodingSetTypeOtherDescription的typeof(MISMOString),令= 0)
[System.Xml.Serialization.XmlElementAttribute(扩展的typeof(续期),令= 0)
[的System.Xml.Serialization .XmlElementAttribute(EmbeddedContentXML的typeof(MISMOXML),令= 0)
[System.Xml.Serialization.XmlElementAttribute(MIMETypeIdentifier的typeof(MISMOIdentifier),令= 0)
[系统.Xml.Serialization.XmlElementAttribute(ObjectCreatedDatetime的typeof(MISMODatetime),令= 0)
[System.Xml.Serialization.XmlElementAttribute(ObjectDescription的typeof(MISMOString),令= 0)
[System.Xml.Serialization.XmlElementAttribute(ObjectEncodingType的typeof(ObjectEncodingEnum),令= 0)
[System.Xml.Serialization.XmlElementAttribute(ObjectEncodingTypeOtherDescription的typeof(MISMOString),令= 0 )
[System.Xml.Serialization.XmlElementAttribute(的ObjectName的typeof(MISMOString),令= 0)
[System.Xml.Serialization.XmlElementAttribute(ObjectURI,typeof运算(字符串) ,数据类型=任何URI,令= 0)
[System.Xml.Serialization.XmlElementAttribute(OriginalCreatorDigestValue的typeof(MISMOValue),令= 0)
[的System.Xml.Serialization。 XmlElementAttribute(引用的typeof(参考),令= 0)
[System.Xml.Serialization.XmlChoiceIdentifierAttribute(ItemsElementName)]
公开名单<对象>项目
{
得到
{
返回this.itemsField;
}

{
this.itemsField =价值;
}
}

[System.Xml.Serialization.XmlElementAttribute(ItemsElementName,令= 1)]
[System.Xml.Serialization.XmlIgnoreAttribute() ]
公开名单< ItemsChoiceType> ItemsElementName
{
得到
{
返回this.itemsElementNameField;
}

{
this.itemsElementNameField =价值;
}
}

[System.Xml.Serialization.XmlAttributeAttribute(表格= System.Xml.Schema.XmlSchemaForm.Qualified,命名空间=HTTP://www.w3。组织/ 1999 / XLink的)]
公共MISMOresourceLink类型
{
得到
{
返回this.typeField;
}

{
this.typeField =价值;
}
}

[System.Xml.Serialization.XmlIgnoreAttribute()]
公共BOOL typeSpecified
{
的get
{
返回this.typeFieldSpecified;
}

{
this.typeFieldSpecified =价值;
}
}

[System.Xml.Serialization.XmlAttributeAttribute(表格= System.Xml.Schema.XmlSchemaForm.Qualified,命名空间=HTTP://www.w3。组织/ 1999 / XLink的)]
公共字符串的作用
{
得到
{
返回this.roleField;
}

{
this.roleField =价值;
}
}

[System.Xml.Serialization.XmlAttributeAttribute(表格= System.Xml.Schema.XmlSchemaForm.Qualified,命名空间=HTTP://www.w3。组织/ 1999 / XLink的)]
公共字符串标题
{
得到
{
返回this.titleField;
}

{
this.titleField =价值;
}
}

[System.Xml.Serialization.XmlAttributeAttribute(表格= System.Xml.Schema.XmlSchemaForm.Qualified,命名空间=HTTP://www.w3。组织/ 1999 / XLink的数据类型=NMTOKEN)]
公共字符串标签
{
得到
{
返回this.labelField;
}

{
this.labelField =价值;
}
}

[System.Xml.Serialization.XmlAttributeAttribute(数据类型=整数)]
公共字符串的SequenceNumber
{
得到
{
返回this.sequenceNumberField;
}

{
this.sequenceNumberField =价值;
}
}

私有静态System.Xml.Serialization.XmlSerializer串行
{
得到
{
如果((串行== NULL))
{
串行=新System.Xml.Serialization.XmlSerializer(typeof运算(FOREIGN_OBJECT));
}
返回串;
}
}

#地区的序列化/反序列化
///<总结>
///当前序列化对象FOREIGN_OBJECT到XML文档
///< /总结>
///<退货和GT; XML字符串值< /回报>
公共虚拟字符串序列化(System.Text.Encoding编码)
{
就是System.IO.StreamReader的StreamReader = NULL;
System.IO.MemoryStream的MemoryStream = NULL;

{
MemoryStream的=新System.IO.MemoryStream();
System.Xml.XmlWriterSettings xmlWriterSettings =新System.Xml.XmlWriterSettings();
xmlWriterSettings.Encoding =编码;
System.Xml.XmlWriter的XmlWriter = XmlWriter.Create(MemoryStream的,xmlWriterSettings);
Serializer.Serialize(XmlWriter的,这一点);
memoryStream.Seek(0,System.IO.SeekOrigin.Begin);
的StreamReader =新就是System.IO.StreamReader(MemoryStream的);
返回streamReader.ReadToEnd();
}
终于
{
如果((的StreamReader = NULL)!)
{
streamReader.Dispose();
}
如果((的MemoryStream = NULL)!)
{
memoryStream.Dispose();
}
}
}

公共虚拟字符串序列化()
{
返回序列化(Encoding.UTF8);
}

///<总结>
///反序列化工作流标记成FOREIGN_OBJECT对象
///< /总结>
///< PARAM NAME =XML>字符串工作流标记反序列化< /参数>
///< PARAM NAME =目标文件>输出FOREIGN_OBJECT对象< /参数>
///< PARAM NAME =例外>输出异常值,如果反序列化失败< /参数>
///<退货和GT;如果此XmlSerializer的可以反序列化的对象;否则为false< /回报>
公共静态布尔反序列化(XML字符串,出FOREIGN_OBJECT OBJ,出System.Exception的除外)
{
例外= NULL;
OBJ =默认(FOREIGN_OBJECT);

{
OBJ =反序列化(XML);
返回真;
}
赶上(System.Exception的前)
{
例外=前;
返回FALSE;
}
}

公共静态布尔反序列化(XML字符串,出FOREIGN_OBJECT OBJ)
{
System.Exception的异常= NULL;
返回反序列化(XML,出OBJ,出除外);
}

公共静态FOREIGN_OBJECT反序列化(XML字符串)
{
System.IO.StringReader stringReader = NULL;

{
stringReader =新System.IO.StringReader(XML);
回报率((FOREIGN_OBJECT)(Serializer.Deserialize(System.Xml.XmlReader.Create(stringReader))));
}
终于
{
如果((stringReader = NULL)!)
{
stringReader.Dispose();
}
}
}

///<总结>
///当前序列化对象FOREIGN_OBJECT到文件
///< /总结>
///< PARAM NAME =文件名> outupt xml文件<的完整路径; /参数>
///< PARAM NAME =例外>输出异常值,如果失败< /参数>
///<退货和GT;真要是能序列化和保存到文件中;否则为false< /回报>
公共虚拟BOOL的SaveToFile(字符串文件名,System.Text.Encoding编码,出来的System.Exception除外)
{
例外= NULL;

{
的SaveToFile(文件名,编码);
返回真;
}
赶上(System.Exception的E)
{
例外= E;
返回FALSE;
}
}

公共虚拟BOOL的SaveToFile(字符串文件名,出System.Exception的除外)
{
返回的SaveToFile(文件名,Encoding.UTF8,出除外);
}

公共虚拟无效的SaveToFile(字符串文件名)
{
的SaveToFile(文件名,Encoding.UTF8);
}

公共虚拟无效的SaveToFile(字符串文件名,System.Text.Encoding编码)
{
System.IO.StreamWriter的StreamWriter = NULL;

{
串的xmlString =序列化(编码);
的StreamWriter =新System.IO.StreamWriter(文件名,假的,Encoding.UTF8);
streamWriter.WriteLine(的xmlString);
streamWriter.Close();
}
终于
{
如果((的StreamWriter = NULL)!)
{
streamWriter.Dispose();
}
}
}

///<总结>
///反序列化XML标记从文件到FOREIGN_OBJECT对象
///< /总结>
///< PARAM NAME =文件名>字符串的XML文件来加载和反序列化< /参数>
///< PARAM NAME =目标文件>输出FOREIGN_OBJECT对象< /参数>
///< PARAM NAME =例外>输出异常值,如果反序列化失败< /参数>
///<退货和GT;如果此XmlSerializer的可以反序列化的对象;否则为false< /回报>
公共静态布尔LoadFromFile(字符串文件名,System.Text.Encoding编码,出来FOREIGN_OBJECT OBJ,出System.Exception的除外)
{
例外= NULL;
OBJ =默认(FOREIGN_OBJECT);

{
OBJ = LoadFromFile(文件名,编码);
返回真;
}
赶上(System.Exception的前)
{
例外=前;
返回FALSE;
}
}

公共静态布尔LoadFromFile(字符串文件名,出FOREIGN_OBJECT OBJ,出System.Exception的除外)
{
返回LoadFromFile(文件名, Encoding.UTF8,出OBJ,出除外);
}

公共静态布尔LoadFromFile(字符串文件名,出FOREIGN_OBJECT OBJ)
{
System.Exception的异常= NULL;
返回LoadFromFile(文件名,出OBJ,出除外);
}

公共静态FOREIGN_OBJECT LoadFromFile(字符串文件名)
{
返回LoadFromFile(文件名,Encoding.UTF8);
}

公共静态FOREIGN_OBJECT LoadFromFile(字符串文件名,System.Text.Encoding编码)
{
System.IO.FileStream文件= NULL;
就是System.IO.StreamReader SR = NULL;

{
档=新System.IO.FileStream(文件名,FileMode.Open,FileAccess.Read);
SR =新就是System.IO.StreamReader(文件编码);
串的xmlString = sr.ReadToEnd();
sr.Close();
file.Close();
返回反序列化(的xmlString);
}
终于
{
如果((文件= NULL)!)
{
file.Dispose();
}
如果((SR = NULL)!)
{
sr.Dispose();
}
}
}
#endregion

#地区的克隆方法
///<总结>
///创建此FOREIGN_OBJECT对象
的克隆///< /总结>
公共虚拟FOREIGN_OBJECT的clone()
{
回报率((FOREIGN_OBJECT)(this.MemberwiseClone()));
}
#endregion
}


解决方案

XmlChoiceIdentifierAttribute 仅与ChoiceIdentifier是一个数组没有一个通用的列表的支持。



中的多种元素

  [System.Xml.Serialization.XmlElementAttribute(ItemsElementName,令= 1)] 
[System.Xml.Serialization.XmlIgnoreAttribute()]
公ItemsChoiceType [] ItemsElementName
{
// ...
}

该错误是混乱,因为它是假设,由于项目是类似数组(列表)和您所选择的标识符是不是你的标识符的选择的类型之前缺席了预选赛数组的数组。但它不是这样的,所以建议完全是误导性的。



注意:从理论上看项目代码(从Microsoft源服务器)不要吨需要是一个数组......在实践中临时序列化类的产生完全爆炸,因为List.length的数字是不公开的(它明确地实现)


Yes I know very generic title, but I'm going to explain now.

Given the class definition below, can someone explain why I would be getting this exception when I invoke the Serialize() method.

{"There was an error reflecting type 'FNM.MISMO_3_0.FOREIGN_OBJECT'."}

{"Type of choice identifier 'ItemsElementName' is inconsistent with type of 'Items'. Please use array of System.Collections.Generic.List`1[[MISMO_3_0.ItemsChoiceType, MISMO_3_0, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]."}

Thank you, Stephen

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.225")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace = "http://www.mismo.org/residential/2009/schemas")]
[System.Xml.Serialization.XmlRootAttribute(Namespace = "http://www.mismo.org/residential/2009/schemas", IsNullable = true)]
public partial class FOREIGN_OBJECT
{

    private List<object> itemsField;

    private List<ItemsChoiceType> itemsElementNameField;

    private MISMOresourceLink typeField;

    private bool typeFieldSpecified;

    private string roleField;

    private string titleField;

    private string labelField;

    private string sequenceNumberField;

    private static System.Xml.Serialization.XmlSerializer serializer;

    public FOREIGN_OBJECT()
    {
        this.itemsElementNameField = new List<ItemsChoiceType>();
        this.itemsField = new List<object>();
    }

    [System.Xml.Serialization.XmlElementAttribute("CharacterEncodingSetType", typeof(CharacterEncodingSetEnum), Order = 0)]
    [System.Xml.Serialization.XmlElementAttribute("CharacterEncodingSetTypeOtherDescription", typeof(MISMOString), Order = 0)]
    [System.Xml.Serialization.XmlElementAttribute("EXTENSION", typeof(EXTENSION), Order = 0)]
    [System.Xml.Serialization.XmlElementAttribute("EmbeddedContentXML", typeof(MISMOXML), Order = 0)]
    [System.Xml.Serialization.XmlElementAttribute("MIMETypeIdentifier", typeof(MISMOIdentifier), Order = 0)]
    [System.Xml.Serialization.XmlElementAttribute("ObjectCreatedDatetime", typeof(MISMODatetime), Order = 0)]
    [System.Xml.Serialization.XmlElementAttribute("ObjectDescription", typeof(MISMOString), Order = 0)]
    [System.Xml.Serialization.XmlElementAttribute("ObjectEncodingType", typeof(ObjectEncodingEnum), Order = 0)]
    [System.Xml.Serialization.XmlElementAttribute("ObjectEncodingTypeOtherDescription", typeof(MISMOString), Order = 0)]
    [System.Xml.Serialization.XmlElementAttribute("ObjectName", typeof(MISMOString), Order = 0)]
    [System.Xml.Serialization.XmlElementAttribute("ObjectURI", typeof(string), DataType = "anyURI", Order = 0)]
    [System.Xml.Serialization.XmlElementAttribute("OriginalCreatorDigestValue", typeof(MISMOValue), Order = 0)]
    [System.Xml.Serialization.XmlElementAttribute("REFERENCE", typeof(REFERENCE), Order = 0)]
    [System.Xml.Serialization.XmlChoiceIdentifierAttribute("ItemsElementName")]
    public List<object> Items
    {
        get
        {
            return this.itemsField;
        }
        set
        {
            this.itemsField = value;
        }
    }

    [System.Xml.Serialization.XmlElementAttribute("ItemsElementName", Order = 1)]
    [System.Xml.Serialization.XmlIgnoreAttribute()]
    public List<ItemsChoiceType> ItemsElementName
    {
        get
        {
            return this.itemsElementNameField;
        }
        set
        {
            this.itemsElementNameField = value;
        }
    }

    [System.Xml.Serialization.XmlAttributeAttribute(Form = System.Xml.Schema.XmlSchemaForm.Qualified, Namespace = "http://www.w3.org/1999/xlink")]
    public MISMOresourceLink type
    {
        get
        {
            return this.typeField;
        }
        set
        {
            this.typeField = value;
        }
    }

    [System.Xml.Serialization.XmlIgnoreAttribute()]
    public bool typeSpecified
    {
        get
        {
            return this.typeFieldSpecified;
        }
        set
        {
            this.typeFieldSpecified = value;
        }
    }

    [System.Xml.Serialization.XmlAttributeAttribute(Form = System.Xml.Schema.XmlSchemaForm.Qualified, Namespace = "http://www.w3.org/1999/xlink")]
    public string role
    {
        get
        {
            return this.roleField;
        }
        set
        {
            this.roleField = value;
        }
    }

    [System.Xml.Serialization.XmlAttributeAttribute(Form = System.Xml.Schema.XmlSchemaForm.Qualified, Namespace = "http://www.w3.org/1999/xlink")]
    public string title
    {
        get
        {
            return this.titleField;
        }
        set
        {
            this.titleField = value;
        }
    }

    [System.Xml.Serialization.XmlAttributeAttribute(Form = System.Xml.Schema.XmlSchemaForm.Qualified, Namespace = "http://www.w3.org/1999/xlink", DataType = "NMTOKEN")]
    public string label
    {
        get
        {
            return this.labelField;
        }
        set
        {
            this.labelField = value;
        }
    }

    [System.Xml.Serialization.XmlAttributeAttribute(DataType = "integer")]
    public string SequenceNumber
    {
        get
        {
            return this.sequenceNumberField;
        }
        set
        {
            this.sequenceNumberField = value;
        }
    }

    private static System.Xml.Serialization.XmlSerializer Serializer
    {
        get
        {
            if ((serializer == null))
            {
                serializer = new System.Xml.Serialization.XmlSerializer(typeof(FOREIGN_OBJECT));
            }
            return serializer;
        }
    }

    #region Serialize/Deserialize
    /// <summary>
    /// Serializes current FOREIGN_OBJECT object into an XML document
    /// </summary>
    /// <returns>string XML value</returns>
    public virtual string Serialize(System.Text.Encoding encoding)
    {
        System.IO.StreamReader streamReader = null;
        System.IO.MemoryStream memoryStream = null;
        try
        {
            memoryStream = new System.IO.MemoryStream();
            System.Xml.XmlWriterSettings xmlWriterSettings = new System.Xml.XmlWriterSettings();
            xmlWriterSettings.Encoding = encoding;
            System.Xml.XmlWriter xmlWriter = XmlWriter.Create(memoryStream, xmlWriterSettings);
            Serializer.Serialize(xmlWriter, this);
            memoryStream.Seek(0, System.IO.SeekOrigin.Begin);
            streamReader = new System.IO.StreamReader(memoryStream);
            return streamReader.ReadToEnd();
        }
        finally
        {
            if ((streamReader != null))
            {
                streamReader.Dispose();
            }
            if ((memoryStream != null))
            {
                memoryStream.Dispose();
            }
        }
    }

    public virtual string Serialize()
    {
        return Serialize(Encoding.UTF8);
    }

    /// <summary>
    /// Deserializes workflow markup into an FOREIGN_OBJECT object
    /// </summary>
    /// <param name="xml">string workflow markup to deserialize</param>
    /// <param name="obj">Output FOREIGN_OBJECT object</param>
    /// <param name="exception">output Exception value if deserialize failed</param>
    /// <returns>true if this XmlSerializer can deserialize the object; otherwise, false</returns>
    public static bool Deserialize(string xml, out FOREIGN_OBJECT obj, out System.Exception exception)
    {
        exception = null;
        obj = default(FOREIGN_OBJECT);
        try
        {
            obj = Deserialize(xml);
            return true;
        }
        catch (System.Exception ex)
        {
            exception = ex;
            return false;
        }
    }

    public static bool Deserialize(string xml, out FOREIGN_OBJECT obj)
    {
        System.Exception exception = null;
        return Deserialize(xml, out obj, out exception);
    }

    public static FOREIGN_OBJECT Deserialize(string xml)
    {
        System.IO.StringReader stringReader = null;
        try
        {
            stringReader = new System.IO.StringReader(xml);
            return ((FOREIGN_OBJECT)(Serializer.Deserialize(System.Xml.XmlReader.Create(stringReader))));
        }
        finally
        {
            if ((stringReader != null))
            {
                stringReader.Dispose();
            }
        }
    }

    /// <summary>
    /// Serializes current FOREIGN_OBJECT object into file
    /// </summary>
    /// <param name="fileName">full path of outupt xml file</param>
    /// <param name="exception">output Exception value if failed</param>
    /// <returns>true if can serialize and save into file; otherwise, false</returns>
    public virtual bool SaveToFile(string fileName, System.Text.Encoding encoding, out System.Exception exception)
    {
        exception = null;
        try
        {
            SaveToFile(fileName, encoding);
            return true;
        }
        catch (System.Exception e)
        {
            exception = e;
            return false;
        }
    }

    public virtual bool SaveToFile(string fileName, out System.Exception exception)
    {
        return SaveToFile(fileName, Encoding.UTF8, out exception);
    }

    public virtual void SaveToFile(string fileName)
    {
        SaveToFile(fileName, Encoding.UTF8);
    }

    public virtual void SaveToFile(string fileName, System.Text.Encoding encoding)
    {
        System.IO.StreamWriter streamWriter = null;
        try
        {
            string xmlString = Serialize(encoding);
            streamWriter = new System.IO.StreamWriter(fileName, false, Encoding.UTF8);
            streamWriter.WriteLine(xmlString);
            streamWriter.Close();
        }
        finally
        {
            if ((streamWriter != null))
            {
                streamWriter.Dispose();
            }
        }
    }

    /// <summary>
    /// Deserializes xml markup from file into an FOREIGN_OBJECT object
    /// </summary>
    /// <param name="fileName">string xml file to load and deserialize</param>
    /// <param name="obj">Output FOREIGN_OBJECT object</param>
    /// <param name="exception">output Exception value if deserialize failed</param>
    /// <returns>true if this XmlSerializer can deserialize the object; otherwise, false</returns>
    public static bool LoadFromFile(string fileName, System.Text.Encoding encoding, out FOREIGN_OBJECT obj, out System.Exception exception)
    {
        exception = null;
        obj = default(FOREIGN_OBJECT);
        try
        {
            obj = LoadFromFile(fileName, encoding);
            return true;
        }
        catch (System.Exception ex)
        {
            exception = ex;
            return false;
        }
    }

    public static bool LoadFromFile(string fileName, out FOREIGN_OBJECT obj, out System.Exception exception)
    {
        return LoadFromFile(fileName, Encoding.UTF8, out obj, out exception);
    }

    public static bool LoadFromFile(string fileName, out FOREIGN_OBJECT obj)
    {
        System.Exception exception = null;
        return LoadFromFile(fileName, out obj, out exception);
    }

    public static FOREIGN_OBJECT LoadFromFile(string fileName)
    {
        return LoadFromFile(fileName, Encoding.UTF8);
    }

    public static FOREIGN_OBJECT LoadFromFile(string fileName, System.Text.Encoding encoding)
    {
        System.IO.FileStream file = null;
        System.IO.StreamReader sr = null;
        try
        {
            file = new System.IO.FileStream(fileName, FileMode.Open, FileAccess.Read);
            sr = new System.IO.StreamReader(file, encoding);
            string xmlString = sr.ReadToEnd();
            sr.Close();
            file.Close();
            return Deserialize(xmlString);
        }
        finally
        {
            if ((file != null))
            {
                file.Dispose();
            }
            if ((sr != null))
            {
                sr.Dispose();
            }
        }
    }
    #endregion

    #region Clone method
    /// <summary>
    /// Create a clone of this FOREIGN_OBJECT object
    /// </summary>
    public virtual FOREIGN_OBJECT Clone()
    {
        return ((FOREIGN_OBJECT)(this.MemberwiseClone()));
    }
    #endregion
}

解决方案

The multiple elements in a XmlChoiceIdentifierAttribute is supported only with the ChoiceIdentifier being an array not a generic list.

[System.Xml.Serialization.XmlElementAttribute("ItemsElementName", Order = 1)]
[System.Xml.Serialization.XmlIgnoreAttribute()]
public ItemsChoiceType[] ItemsElementName
{
    // ...
}

The error is confusing because it's assuming that as Items is array-like (A list) and your choice identifier isn't an array you missed the array qualifier before the type of the choice of identifier. But it isn't the case, so the suggestion is completely misleading.

Note: Seeing the code (from the microsoft source server) in theory Items don't need to be an array... in practice the generation of the temporary serialization class completely explode because List.Length isn't public (it's implemented explicitly)

这篇关于.NET XML序列化错误(有一个错误的反射式)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆