why is ASCII.GetBytes returning wrong bytes

maddy

New Member
Im creating a class and converting it into xml. The problem is that when i convert the class xml string into bytes
the \[code\]ASCII.GetBytes\[/code\] return a byte array with
an extra character in the beginning of the \[code\]ascArray\[/code\]It's always a ? character so the xml starts like this\[code\]?<?xml version="1.0" encoding="utf-8"?>\[/code\]Why is this happening?This is the code:\[code\] WorkItem p = new WorkItem(); // Fill the class with whatever need to be sent to client OneItem posts1 = new OneItem(); posts1.id = "id 1"; posts1.username = "hasse"; posts1.message = "hej again"; posts1.time = "time1"; p.setPost(posts1); OneItem posts2 = new OneItem(); posts2.id = "id 2"; posts2.username = "bella"; posts2.message = "hej again again"; posts2.time = "time2"; p.setPost(posts2); // convert the class WorkItem to xml MemoryStream memoryStream = new MemoryStream(); XmlSerializer xs = new XmlSerializer(typeof(WorkItem)); XmlTextWriter xmlTextWriter = new XmlTextWriter(memoryStream, Encoding.UTF8); xs.Serialize(xmlTextWriter, p); // send the xml version of WorkItem to client byte[] data = http://stackoverflow.com/questions/11027119/memoryStream.ToArray(); clientStream.Write(data, 0, data.Length); Console.WriteLine(" send.." + data); clientStream.Close();\[/code\]
 
Back
Top