0

I am soap serializing multiple objects and appending them to a single file,then I am desirializing to have all the objects to tree view

I am using this part of code of desirialization

FileStream fs = new FileStream(fName, FileMode.Open);
while (fs.Position < fs.Length)
{
    arraylizt.Add(sf.Deserialize(fs));
}

It works well, but sometimes the last object in the file is not desirialized.
I am not getting why its not desirializing the final object sometimes

Please help me or suggest me any other way to deserialize

CharlesB
  • 86,532
  • 28
  • 194
  • 218
  • can you more code? the problem may appear at a higher level. – Steve B Jun 11 '12 at 08:21
  • I don't think problem may be in higher level the following code i am using for serialization FileStream fs = new FileStream(fName, FileMode.Append); SoapFormatter sf = new SoapFormatter(); foreach (object item in temp) { sf.Serialize(fs, item); } fs.Close(); please help me – user1439419 Jun 11 '12 at 11:55
  • I had gone debug mode and i am seeing file stream position is pointing at the end of file after it deserialize some objects for ex if a object graph ends at position 82772 but position is pointing 89532 skipping last object to deserialize. – user1439419 Jun 12 '12 at 08:39

1 Answers1

0

Have you ensure you've flushed your stream upon writing before close (or closed the writer rather than the underlying stream).

Jeff Watkins
  • 6,343
  • 16
  • 19
  • I am not flushed my stream before closing r u suggesting wil it solve the problem if so I will try now.... – user1439419 Jun 11 '12 at 08:27
  • It should do, there is a write buffer (as you're using a stream) and it doesn't write until it hit a certain size. Try it! – Jeff Watkins Jun 11 '12 at 08:30
  • I have tried flush before closing stream the problem still remaining – user1439419 Jun 11 '12 at 08:39
  • I had gone debug mode and i am seeing file stream position is pointing at the end of file after it deserialize some objects for ex if a object graph ends at position 82772 but position is pointing 89532 skipping last object to deserialize. – user1439419 Jun 12 '12 at 10:44