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 UTF8ByteArrayTo String(Byte[] characters)
{
UTF8Encoding encoding = new UTF8Encoding();
String constructedStri ng = encoding.GetStr ing(characters) ;
return (constructedStr ing);
}
XmlInput inp = new XmlInput();
inp.AddSomethin g();
MemoryStream memoryStream = new MemoryStream();
memoryStream.Po sition = 0;
XmlSerializer xs = new XmlSerializer(t ypeof(XmlInput) );
XmlTextWriter xmlTextWriter = new XmlTextWriter(m emoryStream, Encoding.UTF8);
xs.Serialize(xm lTextWriter, inp);
memoryStream = (MemoryStream)x mlTextWriter.Ba seStream;
XmlizedString = UTF8ByteArrayTo String(memorySt ream.ToArray()) ;
System.Console. WriteLine(Xmliz edString);
... output xml all looks ok ...apart from leading char
"?<?xml version=\"1.0\" encoding=\"utf-8\"?><XmlInpu t xmlns:xsd=\"htt p://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"htt p://www.w3.org/2001/XMLSchema-instance\" xmlns=\"urn:My. XmlInput\"><Ser vice>XXX</Service</XmlInput>"