Click here to Skip to main content
15,914,013 members
Home / Discussions / C#
   

C#

 
GeneralRe: How thread safe are static fields? Pin
Mark Salsbery15-Aug-08 13:29
Mark Salsbery15-Aug-08 13:29 
GeneralRe: How thread safe are static fields? Pin
JoeRip15-Aug-08 13:47
JoeRip15-Aug-08 13:47 
QuestionDo I still need to LOCK a Synchronized Queue? Pin
JoeRip15-Aug-08 11:51
JoeRip15-Aug-08 11:51 
AnswerRe: Do I still need to LOCK a Synchronized Queue? Pin
Wendelius15-Aug-08 12:30
mentorWendelius15-Aug-08 12:30 
GeneralRe: Do I still need to LOCK a Synchronized Queue? Pin
JoeRip15-Aug-08 12:33
JoeRip15-Aug-08 12:33 
GeneralRe: Do I still need to LOCK a Synchronized Queue? Pin
Wendelius15-Aug-08 12:43
mentorWendelius15-Aug-08 12:43 
GeneralRe: Do I still need to LOCK a Synchronized Queue? Pin
JoeRip15-Aug-08 12:49
JoeRip15-Aug-08 12:49 
QuestionDeserialization, after GZipStream it´s possible?? (What is Wrong??) Pin
Guilherme Morais15-Aug-08 11:46
Guilherme Morais15-Aug-08 11:46 
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<string> p3;
                List<string> p1 = new List<string>();
                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<string>)Serializador.Deserialize(msUnZip);:mad:
                
            }
</string></string></string></string>


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, data.Length);
                gzip.Close();
                return output.ToArray();
            }

            public static byte[] Decompress(byte[] data)
            {
                MemoryStream input = new MemoryStream();
                input.Write(data, 0, data.Length);
                input.Position = 0;
                GZipStream gzip = new GZipStream(input,
                                  CompressionMode.Decompress, true);
                MemoryStream output = new MemoryStream();
                byte[] buff = new byte[64];
                int read = -1;
                read = gzip.Read(buff, 0, buff.Length);
                while (read > 0)
                {
                    output.Write(buff, 0, read);
                    read = gzip.Read(buff, 0, buff.Length);
                }
                gzip.Close();
                return output.ToArray();
            }
        }
Font: http://www.codeproject.com/KB/viewstate/ViewStateCompression.aspx[^]
AnswerRe: Deserialization, after GZipStream it´s possible?? (What is Wrong??) Pin
Guilherme Morais18-Aug-08 4:14
Guilherme Morais18-Aug-08 4:14 
QuestionHow to notify c# application from javascript Pin
tomc15-Aug-08 8:54
tomc15-Aug-08 8:54 
AnswerRe: How to notify c# application from javascript Pin
Pete O'Hanlon15-Aug-08 9:01
mvePete O'Hanlon15-Aug-08 9:01 
QuestionC# Code To Change System Date/Time Doesn't Work Pin
Kevin Marois15-Aug-08 8:24
professionalKevin Marois15-Aug-08 8:24 
AnswerRe: C# Code To Change System Date/Time Doesn't Work Pin
Pete O'Hanlon15-Aug-08 8:52
mvePete O'Hanlon15-Aug-08 8:52 
AnswerRe: C# Code To Change System Date/Time Doesn't Work Pin
Mark Salsbery15-Aug-08 9:00
Mark Salsbery15-Aug-08 9:00 
GeneralRe: C# Code To Change System Date/Time Doesn't Work Pin
Kevin Marois15-Aug-08 10:24
professionalKevin Marois15-Aug-08 10:24 
GeneralRe: C# Code To Change System Date/Time Doesn't Work Pin
Mycroft Holmes15-Aug-08 15:34
professionalMycroft Holmes15-Aug-08 15:34 
AnswerRe: C# Code To Change System Date/Time Doesn't Work Pin
Thomas Stockwell16-Aug-08 12:57
professionalThomas Stockwell16-Aug-08 12:57 
GeneralRe: C# Code To Change System Date/Time Doesn't Work Pin
alefaga8-May-09 5:00
alefaga8-May-09 5:00 
QuestionMask Internet IP Address Pin
maliaslam15-Aug-08 6:49
maliaslam15-Aug-08 6:49 
GeneralRe: Mask Internet IP Address Pin
Pete O'Hanlon15-Aug-08 8:31
mvePete O'Hanlon15-Aug-08 8:31 
AnswerRe: Mask Internet IP Address Pin
Manas Bhardwaj15-Aug-08 9:10
professionalManas Bhardwaj15-Aug-08 9:10 
GeneralRe: Mask Internet IP Address Pin
Pete O'Hanlon15-Aug-08 9:13
mvePete O'Hanlon15-Aug-08 9:13 
GeneralRe: Mask Internet IP Address Pin
maliaslam16-Aug-08 2:57
maliaslam16-Aug-08 2:57 
GeneralRe: Mask Internet IP Address Pin
maliaslam10-Sep-08 0:27
maliaslam10-Sep-08 0:27 
QuestionCSC Pin
Muammar©15-Aug-08 5:28
Muammar©15-Aug-08 5:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.