0

I use this following code but it gives error

Service1.svc.cs

 public static byte[] SerializeObject<T>(T obj)
    {
        using (MemoryStream ms = new MemoryStream())
        {
            using (XmlDictionaryWriter writer = XmlDictionaryWriter.CreateBinaryWriter(ms))
            {
                DataContractSerializer dcs = new DataContractSerializer(typeof(T));
                dcs.WriteObject(writer, obj); writer.Flush();
                return ms.ToArray();
            }
        }
    }

client code Windows phone

public static T DeserializeObject<T>(byte[] xml) 
    { 
        using (MemoryStream memoryStream = new MemoryStream(xml)) 
        {
            using (XmlDictionaryReader reader = XmlDictionaryReader.CreateBinaryReader(memoryStream, XmlDictionaryReaderQuotas.Max)) 
            {
                DataContractSerializer dcs = new DataContractSerializer(typeof(T)); 
                return (T)dcs.ReadObject(reader); 
            } 
        } 
    }

I call this DeserializeObject from below code

   void svc_Get_Conn(object send, GetConnCompletedEventArgs e)
    {  
        CookieContainer con =DeserializeObject<CookieContainer>(e.Result);
    }

This gives following error

Message = "Type 'System.Net.PathList' with data contract name 'PathList:http://schemas.datacontract.org/2004/07/System.Net' is not expected. Consider using a DataContractResolver or add any types not known statically to the list of known types - for example, by using...

How to solve this?

Amol
  • 1,431
  • 2
  • 18
  • 32

1 Answers1

0

CookieContainer can't be serializable. Check this workaround

cheers

Community
  • 1
  • 1