0

我使用以下代码,但它给出了错误

服务1.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();
            }
        }
    }

客户端代码 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); 
            } 
        } 
    }

我从下面的代码中调用这个DeserializeObject

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

这给出了以下错误

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...

如何解决这个问题?

4

1 回答 1

0

CookieContainer 不能序列化。检查解决方法

干杯

于 2012-09-13T11:14:14.047 回答