Error Deserializing Xml to Object – xmlns=” was not expected

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.

Leave a Comment