I am reading an XML response, the XML looks like this:
<?xml version=""1.0"" encoding=""UTF-8""?>
<Errors>
<Error>Error Msg 1</Error>
<Error>Error Msg 2</Error>
</Errors>
I have classes for response:
public class Error
{
public string ErrorMessage { get; set; }
}
public class OrderCreationResponse
{
public Error[] Errors { get; set; }
...
}
and I try to create an OrderCreationResponse using this code:
var orderCreationResponse = xDocument.Root
.Elements("Errors")
.Select(x => new OrderCreationResponse
{
Errors = x.Elements("Error").Select(c => new Error
{
ErrorMessage = (string) c.Element("Error").Value
}).ToArray()
}).FirstOrDefault();
But it always returns null. What am I doing wrong?