Monday, 6 April 2015

c# xml read There is an error in XML document (2, 2).

This is my xml
<?xml version='1.0' encoding='utf-16'?>
<Message>
<FirstName>Hunt</FirstName>
<LastName>DAvid</LastName>
</Message>
This is my code...
string xml = File.ReadAllText("c:\\Message.xml");
var result = DeserializeFromXml<Message>(xml);
I was getting error..
Solution:
Message class is missing XmlRoot

[Serializable, XmlRoot("Message")]
public class Message
{
public string FirstName { get; set; }
public string LastName { get; set; }
}