my Xml file :
You are not casting x you are casting x.Descendants(). x.Descendants() returns a collection, hence the plural method semantic. Off the top of my head you should be able to do x.Descendants("CustomerId").FirstOrDefault() as XElement
x
x.Descendants()
x.Descendants("CustomerId").FirstOrDefault() as XElement