Re: Serialization Question

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Kyril Magnos (kyril.magnos_at_yahoo.com)
Date: 07/16/04


Date: Fri, 16 Jul 2004 13:41:19 -0700

Serialization does not support appending (at least not that I have read
anywhere, MSDN does not explicitly say this, but given how serialization
works, I can't imagine that it does work).

If you need to modify a serialized component, then you should deserialize it
first, then make your changes and then serialize it back, overwriting the
original file.

-- 
HTH
Kyril Magnos
Question of the day:
    What is Mono?
        A) Disease where the lymph nodes become swollen.
        B) A single sound
        C) A synonym for one
        D) A port of .NET meant to royally irritate MSFT
        E) All of the above.
"Silesian" <nospam@spamthis.com> wrote in message 
news:10fgeh5ln8dgv04@corp.supernews.com...
|I realize that this is a newbie question but maybe someone will be able to
| tell me what am I doing wrong.
| createFile() gets called each time I have the user generate some numbers
| which then get added to the binlist ArrayList.
| I'm able to serialize and deserialize the Arraylist.  However, when I
| deserialize the ArrayList, it will only show the first set of ints.  I
| looked at the bin file and it does get appended to each time.  Any help 
will
| be appreciated.
| Rich
|
| private void createFile()
| {
|    foreach (int a in num)
| {
|    binlist.Add (a);
| }
|
| Stream streamAppend = File.Open("Numbers.bin",FileMode.Append);
| bf.Serialize (streamAppend,binlist);
| streamAppend.Close ();
| Stream streamRead = File.OpenRead("Numbers.bin");
| binlist=(ArrayList)bf.Deserialize (streamRead);
| streamRead.Close ();
| MessageBox.Show (binlist.Count .ToString ());
| for(int i = 0; i < binlist.Count ; i ++)
| {
|    MessageBox.Show (binlist[i].ToString ());
| }
|
| 


Relevant Pages

  • Re: Deserialize, CryptoStream, and NetworkStream
    ... the program works as expected and the server can deserialize the ... the zero byte signal from the stream is essential. ... > When you don't use a CryptoStream the Deserialize call can read the data ... the serialization protocol ought to be able to do exactly what ...
    (microsoft.public.dotnet.security)
  • Re: Binary serialization
    ... implement a custom serialisation method for every object I create if the the ... objects's DATA members are the only part of the object I want to store. ... then written to the stream by the base class. ... Is serialization the answer to the above problem? ...
    (microsoft.public.dotnet.general)
  • Re: Binary serialization
    ... The problem here is that you're working with managed objects. ... Serialization in managed code is that the object can be de-serialized from ... objects's DATA members are the only part of the object I want to store. ... then written to the stream by the base class. ...
    (microsoft.public.dotnet.general)
  • Re: A generic error occurred in GDI+. InteropServices.ExternalException
    ... The code in the previous message shows I dispose the stream after ... I guess there is a possiblity that the serialization is not done when I ... Microsoft Online Community Support ...
    (microsoft.public.dotnet.framework.interop)
  • Re: Binary serialization
    ... I told you yesterday that you could do this with custom binary ... DATA members from the class in question the method of writing each ... then written to the stream by the base class. ... Is serialization the answer to the above problem? ...
    (microsoft.public.dotnet.general)