I generated a class from an XSD using XSDObjectGen, when i try to create an xml serialized string from it i get an invalid char in position 1,1
The code i use to serialise the object is pasted below.. lifted from http://www.dotnetjohn.com/articles.aspx?articleid=173
The char at position 1 is displayed as a "?" so some encoding is taking place.. it has a hex value is 0xFeFF
Can anyone spot an obvious mistake??
private String UTF8ByteArrayToString(Byte[] characters)
{
UTF8Encoding encoding = new UTF8Encoding();
String constructedString = encoding.GetString(characters);
return (constructedString);
}
XmlInput inp = new XmlInput();
inp.AddSomething();
MemoryStream memoryStream = new MemoryStream();
memoryStream.Position = 0;
XmlSerializer xs = new XmlSerializer(typeof(XmlInput));
XmlTextWriter xmlTextWriter = new XmlTextWriter(memoryStream, Encoding.UTF8);
xs.Serialize(xmlTextWriter, inp);
memoryStream = (MemoryStream)xmlTextWriter.BaseStream;
XmlizedString = UTF8ByteArrayToString(memoryStream.ToArray());
System.Console.WriteLine(XmlizedString);
... output xml all looks ok ...apart from leading char
"?<?xml version=\"1.0\" encoding=\"utf-8\"?><XmlInput xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"urn:My.XmlInput\"><Service>XXX</Service</XmlInput>"