Deserialization Error: The XML element 'name' from namespace '' is already present in the current scope

前端 未结 9 1202
旧巷少年郎
旧巷少年郎 2020-12-18 07:43

This is my first time using XML Serialization and this is driving me absolutely nuts after 2 days of trying to troubleshoot this.

I get this error w

9条回答
  •  误落风尘
    2020-12-18 08:15

    Personally, I wouldn't use constants here - they make it hard to spot errors (and since you probably aren't re-using them, don't add much). For example:

        [XmlElement (ElementName = ElementConstants.AlbumName, DataType = "string")]
        public string AlbumID { get; set; }
    ...
        [XmlElement(ElementName = ElementConstants.AlbumName, DataType = "string")]
        public string AlbumName { get; set; }
    

    Looks suspect to me...

    An easier approach is to write the xml you want to a file (foo.xml, say) and use:

    xsd foo.xml
    xsd foo.xsd /classes
    

    Then look at foo.cs.

提交回复
热议问题