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

前端 未结 9 1203
旧巷少年郎
旧巷少年郎 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:24

    Yes - album is definitely not the root node in your XML.

    What I would recommend you do is create a GetAlbumsResponse class which contains a list of albums, and move your deserialize code to the wrapper class.

    Basically, remove the root element from your Album class definition, and :

      [XmlRoot (ElementName="GetAlbums_response")]
    public class GetAlbumsResponse
    {
        #region Constructors
    
        public GetAlbumsResponse()
        {
    
        }
    
        #endregion
    
    
    
        [XmlArray(ElementName="album")]
        public List Albums{get;set;}
    
        ... deserialization code...
    

    }

提交回复
热议问题