c# LINQ to XML null value exception



This is my code:



List<Customer> customersList =
(
from e in XDocument.Load(file).Root.Elements("cust")
select new Customer
{
CustomerID = (int)e.Element("custid"),
FirstName = (string)e.Element("fname"),
LastName = (string)e.Element("lname"),
ShowsNumber = (int)e.Element("count_noshow"),
VisitNumber = (int)e.Element("count_resos"),
Cancellation = (int)e.Element("count_cancel"),
}).ToList();


I got {"Value cannot be null.\r\nParameter name: element"} exception on the customerList = (....) part of the code,


I can see the XML, it has a lot of cust nodes under the root node.


could you help me please?


Many thanks Best regards,


No comments:

Post a Comment