I am trying to use the Visual Studio editor to create XML files in the Resources area of an Assembly in C#. The files appear perfectly correct in the XML editor and honour my schema (recognising the elements and attributes). However when I try to read them (from the Resources) they fail because they consistently have 3 spurious characters at the start of the file ( or #EF #BB #BF).
These characters do NOT appear in the editor but they are there in an external binary editor. When I remove them manualy the files behave properly.
What can I do to create XML files reliably in the Resources area?
After first 2 replies I modified the question to
"How do I read a resources file to avoid including the byte order mark?"
The XML editor creates an XML file by default with the encoding UTF-8 and adds the XML declaration:
<?xml version="1.0" encoding="utf-8" ?>
Presumably it also adds the encoding (which in UTF-8 is 3 bytes as above). The following method (found by a friend) seems to read the bytes without having to know the encoding:
String ss = new StreamReader( new MemoryStream(bytes), true ).ReadToEnd();
and this now does not try to parse the BOM as part of content.
They're not spurious. They're the byte order mark indicating UTF-8.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With