I'm trying to deserialize an XML stream and getting the following error:
Error in line 1 position 7. Expecting element 'auth' from namespace 'http://schemas.datacontract.org/2004/07/Veracross'.. Encountered 'Element' with name 'auth', namespace ''.
The XML stream I'm deserializing looks like this:
<auth>
<status>success</status>
<username>jsmith</username>
<person_pk>1234</person_pk>
<security_roles>Parent</security_roles>
</auth>
My code:
[DataContract(Name = "auth")]
public class Authorization
{
[DataMember(Name = "status")]
public string Status { get; set; }
[DataMember(Name = "username")]
public string UserName { get; set; }
[DataMember(Name = "security_roles")]
public string SecurityRoles { get; set; }
}
// Some code here receiving the XML and storing in a string (xmlData)
DataContractSerializer serializer = new DataContractSerializer(typeof(Authorization));
MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(xmlData));
Authorization Auth = (Authorization)serializer.ReadObject(stream);
I presume it's not happy with the barebones XML file (no header info) but I don't have any control over it. It is consumed from a RESTful service.