Here is my code for Deserializer for byte[] object
public static T DeserializeObject<T>(byte[] xml)
{
//BinaryFormatter xs = new BinaryFormatter();
MemoryStream memoryStream=new MemoryStream(xml);
XmlSerializer xs = new XmlSerializer(typeof(T));
return (T)xs.Deserialize(memoryStream);
}
It gives error There is an error in XML document
InnerException Invalid character in the given encoding
How can I Deserialize it?
Calling funcation:
void svc_Get_Conn(object send, GetConnCompletedEventArgs e)
{
CookieContainer con =DeserializeObject<CookieContainer>(e.Result);
}
Following funcation is from Service1.svc.cs
public static byte[] SerializeObject<T>(T obj)
{
try
{
using (MemoryStream memoryStream = new MemoryStream())
{
BinaryFormatter xs = new BinaryFormatter();
xs.Serialize(memoryStream, obj);
return memoryStream.ToArray();
}
}
catch
{
return null;
}
}