不使用GZipStream,只使用SerializationFormat.Binary时能通过,
使用GZipStream时在解压缩时总是出错,哪位高人帮看一下,代码如下:压缩:
public static byte[] CompressDataSet(DataSet data)
{
    try
    {
      BinaryFormatter ser = new BinaryFormatter();
      MemoryStream unCompressMS = new MemoryStream();
      data.RemotingFormat = SerializationFormat.Binary;
      ser.Serialize(unCompressMS, data);      MemoryStream compressMs = new MemoryStream();
      GZipStream compressedStream = new GZipStream(compressMs, CompressionMode.Compress, true);
      compressedStream.Write(unCompressMS.ToArray(), 0, unCompressMS.ToArray().Length);      return compressMs.ToArray();
     }
     catch (ApplicationException ex)
     {
        return null;
     }
}解压缩:
public static DataSet DecompressDataSet(byte[] data)
{
  try
  {
    MemoryStream unCompressMS = new MemoryStream();
    MemoryStream compressMS = new MemoryStream(data);
    Stream decompressedStream = new GZipStream(compressMS, CompressionMode.Decompress, true);    BinaryFormatter ser = new BinaryFormatter();
    return (DataSet)ser.Deserialize(decompressedStream);
   }
   catch (ApplicationException ex)
   {
       return null;
   }
}谢谢~ 紧急~

解决方案 »

  1.   

    解压出错信息:未处理的“System.Runtime.Serialization.SerializationException”类型的异常出现在 mscorlib.dll 中。其他信息: 在分析完成之前就遇到流结尾。
      

  2.   

    http://support.microsoft.com/?id=818412
      

  3.   

    是个BUG,给出了解决方案. 加油
      

  4.   

    看了,不知所云~奇怪,用FileStream又可以了,用MemoryStream不行
      

  5.   

    compressedStream.Write(unCompressMS.ToArray(), 0, unCompressMS.ToArray().Length);compressedStream.Close();//你缺这句return compressMs.ToArray();
      

  6.   

    惭愧啊,就是这个问题,我说怎么压出来的都不完整啊
    谢谢 Jointan 兄弟太不细心了,呵呵,面壁...
      

  7.   

    你好,可以加我qq吗? 275222920 我想讨论一下gzip的问题^_^