Error Deserializing Xml to Object - xmlns='' was not expected

后端 未结 3 445
情歌与酒
情歌与酒 2020-11-29 04:55

I am having real trouble trying to deserialize some XML and was hoping someone can offer some assistance. I have read a lot of similar posts but I am unable to resolve this.

3条回答
  •  情深已故
    2020-11-29 05:44

    Simply take off the Namespace =:

    [XmlRoot("register-account"), XmlType("register-account")]
    public class RegisterAccountResponse {...}
    

    since your xml doesn't seem to be in an xml-namespace. Also, [Serializable] isn't used by XmlSerializer.

    If your xml was using a namespace it would have an xmlns at the root.

    Also, to help with callers you could add where T : class, new() (the , new() being the addition) to your Deserialize method, since XmlSerializer demands a public parameterless constructor.

提交回复
热议问题