Women in Technology

Hear us Roar



Article:
  .NET Serialization, Part 1
Subject:   MemoryStream.Position
Date:   2004-03-11 09:12:28
From:   neofight
Just wondering - has anyone run into an error when deserializing? After having problems.. I found that I had to set position=0 before attempting to deserialize my object.


EX:


Dim oxs As New BinaryFormatter()
Dim ms As New MemoryStream()
Dim dl As New DocumentList()


ms = ViewState("bleh")
ms.Position = 0


dl = oxs.Deserialize(ms)

Full Threads Oldest First

Showing messages 1 through 2 of 2.

  • MemoryStream.Position
    2006-07-19 07:29:18  toddstibor [View]

    After writing to a stream, the position of the stream is at the end of the stream. If you try to immediatly read from the exact same stream, you will start to read from the end, where you left of writing. Therefore, you need to rewind the stream to the beginning before you read from it.

    During normal operations, this is not a problem because you are writing to one end of a "pipe" with one stream object, and reading from the other end of the "pipe" with another stream object; usually, the ends of the "pipe" are in different processes anyway.
  • MemoryStream.Position
    2004-03-11 09:14:04  neofight [View]

    Otherwise - great concise article, really enjoyed it!