Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Deserialization, after GZipStream it´s possible?? (What is Wrong??)

Deserialization, after GZipStream it´s possible?? (What is Wrong??)

Scheduled Pinned Locked Moved C#
helpquestiondatabasejsonannouncement
2 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    Guilherme Morais
    wrote on last edited by
    #1

    Hi, everyone... I have a stream and put in a GZipStream, save in SQL 2005, after that I load this stream from sql 2005 and try to deserialize from BinaryFormatter. This will be the GOLD, for now a simple serializable-Compress-Decompress-Deserializable is very fine... But, I´m getting a error: "Binary stream '0' does not contain a valid BinaryHeader. Possible causes are invalid stream or object version change between serialization and deserialization." Any help? My Code:

    public static void Main()
    {

                List p3;
                List p1 = new List();
                p1.Add("Brazil");
                p1.Add("Error");
                p1.Add("Serializable");
    
    
                Stream Serial = new MemoryStream();
                FileStream fileStream = new FileStream("Teste.bin", FileMode.Create, FileAccess.ReadWrite, FileShare.None);
                //BinaryFormatter teste = new BinaryFormatter();
                Processo \_Retorno = new Processo();
                BinaryFormatter teste = new BinaryFormatter();
                teste.Serialize(Serial, p1);
                byte\[\] buffer = new byte\[Serial.Length\];
                Serial.Read(buffer, 0, buffer.Length);
                fileStream.Write(buffer, 0, buffer.Length);
                fileStream.Close();
                //teste.Serialize(fileStream, \_Retorno );
                byte\[\] Compremido = Compressor.Compress(buffer);
                //FileStream destino = new FileStream("Teste.ZIP", FileMode.Create, FileAccess.ReadWrite, FileShare.None);
                //destino.Write(Compremido,0,Compremido.Length  );
                //destino.Close();
                byte\[\] Descompremido = Compressor.Decompress(Compremido);
                MemoryStream msUnZip = new MemoryStream();
                msUnZip.Write(Descompremido, 0, Descompremido.Length);
                msUnZip.Seek(0, SeekOrigin.Begin);
                BinaryFormatter Serializador = new BinaryFormatter();
                p3 = (List)Serializador.Deserialize(msUnZip);:mad:
                
            }
    

    public static class Compressor
    {

            public static byte\[\] Compress(byte\[\] data)
            {
                MemoryStream output = new MemoryStream();
                GZipStream gzip = new GZipStream(output,
                                  CompressionMode.Compress, true);
                gzip.Write(data, 0, dat
    
    G 1 Reply Last reply
    0
    • G Guilherme Morais

      Hi, everyone... I have a stream and put in a GZipStream, save in SQL 2005, after that I load this stream from sql 2005 and try to deserialize from BinaryFormatter. This will be the GOLD, for now a simple serializable-Compress-Decompress-Deserializable is very fine... But, I´m getting a error: "Binary stream '0' does not contain a valid BinaryHeader. Possible causes are invalid stream or object version change between serialization and deserialization." Any help? My Code:

      public static void Main()
      {

                  List p3;
                  List p1 = new List();
                  p1.Add("Brazil");
                  p1.Add("Error");
                  p1.Add("Serializable");
      
      
                  Stream Serial = new MemoryStream();
                  FileStream fileStream = new FileStream("Teste.bin", FileMode.Create, FileAccess.ReadWrite, FileShare.None);
                  //BinaryFormatter teste = new BinaryFormatter();
                  Processo \_Retorno = new Processo();
                  BinaryFormatter teste = new BinaryFormatter();
                  teste.Serialize(Serial, p1);
                  byte\[\] buffer = new byte\[Serial.Length\];
                  Serial.Read(buffer, 0, buffer.Length);
                  fileStream.Write(buffer, 0, buffer.Length);
                  fileStream.Close();
                  //teste.Serialize(fileStream, \_Retorno );
                  byte\[\] Compremido = Compressor.Compress(buffer);
                  //FileStream destino = new FileStream("Teste.ZIP", FileMode.Create, FileAccess.ReadWrite, FileShare.None);
                  //destino.Write(Compremido,0,Compremido.Length  );
                  //destino.Close();
                  byte\[\] Descompremido = Compressor.Decompress(Compremido);
                  MemoryStream msUnZip = new MemoryStream();
                  msUnZip.Write(Descompremido, 0, Descompremido.Length);
                  msUnZip.Seek(0, SeekOrigin.Begin);
                  BinaryFormatter Serializador = new BinaryFormatter();
                  p3 = (List)Serializador.Deserialize(msUnZip);:mad:
                  
              }
      

      public static class Compressor
      {

              public static byte\[\] Compress(byte\[\] data)
              {
                  MemoryStream output = new MemoryStream();
                  GZipStream gzip = new GZipStream(output,
                                    CompressionMode.Compress, true);
                  gzip.Write(data, 0, dat
      
      G Offline
      G Offline
      Guilherme Morais
      wrote on last edited by
      #2

      JUST for awnser this... It´s necessary to put

      Serial.Seek(0, SeekOrigin.Begin);

      Between:

      byte[] buffer = new byte[Serial.Length];
      Serial.Read(buffer, 0, buffer.Length);

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups