score:2

Hi everybody thank you all to your input, the binary dump in my question is simply a dump from VS's memory dump window of the 'file' variable.

@Jon Skeet you actually kind of answered the question but by incident as the binary 8 byte header (or 11 bytes with the 3 byte UTF header) is perfectly fine.

The simple answer to my problem was that I was contructing the XDocument from the text reader rather than calling the static Load function on it. Doh!

score:6

As noted in comments, the first 8 bytes look like they don't belong at the start of an XML file. The next three bytes are a UTF-8 BOM, which is fine. You should work out where those 8 bytes came from, and whether you should always expect them to be there.

If they'll always be there and you want them to be there, simplest way of fixing this is to just move the stream before reading:

MemoryStream stream = new MemoryStream(file);
stream.Position = 8;
XDocument doc = XDocument.Load(stream);

Alternatively, without loading all the data first:

XDocument doc;
using (Stream input = File.OpenRead("test.xml"))
{
    input.Position = 8;
    doc = XDocument.Load(input);
}

Related Query

More Query from same tag