In the following code, I serialize an object into an XML string.
But when I try to read this XML string into an XDocument
It's because the data contains the unicode or utf8 BOM marks at the start of the stream.
You need to skip past any Byte Order Marks in the stream - you can identify these from the System.Text.Encoding.GetPreamble() method.