title: De-serializing objects from a binary file
body: <p>I am using methods to serialize and de-serialize objects to binary file that I have found described and discussed here on stackoverflow.  among others in following link: <a href="https://stackoverflow.com/questions/21080839/pulling-objects-from-binary-file-and-putting-in-listt">Pulling objects from binary file and putting in List&lt;T&gt;</a> The serialisation process is working fine,  I see the file growing when objects are appended to it and when reading with deserialization the problem is that I only get the part of the list that was written in the first write to file.  The data retrieved seem correct, but I do not get to read beyond the first number of objects that were in the list in the first &quot;write&quot; operation.  it is like the file position is always set to zero.</p>
  <p>can the read operation be looped or controlled in any way to forced it to read the entire file?</p>
  <p>Appreciate your comments on this</p>
  <p>Thor</p>
  <pre><code>  class singleBlob
      {
          public Bitmap bmpIndividualFish;
          public Int64 idNumber;
          public float area;
          public float areaRatio; 
      }
  
      class writeToFile 
      {
  
          public void write( List&lt;singleBlob&gt; listOfBlobs)
          {
              string dir = @&quot;D:\temp&quot;;
              string serFileName = Path.Combine(dir, &quot;fIndividualFish.bin&quot;);
              
              //serialize
              using (Stream streamw = File.Open(serFileName, FileMode.Append))
              {
                  var bformatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
  
                  bformatter.Serialize(streamw, listOfBlobs);
                  //streamw.Close(); 
              }
  
          }
  
          public List&lt;singleBlob&gt; read()
          {
              string dir = @&quot;D:\temp&quot;;
              string serFileName = Path.Combine(dir, &quot;fIndividualFish.bin&quot;);
  
              //deserialize
              using (Stream stream = File.Open(serFileName, FileMode.Open,FileAccess.Read))
              {
                  var bformatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
  
                  List&lt;singleBlob&gt; listOfBlobs = (List&lt;singleBlob&gt;)bformatter.Deserialize(stream);
  
                  //stream.Close();
                  return listOfBlobs; 
              }
          }
  
     
  </code></pre>