ObjectStateFormatter.Deserialize Method (Stream)

 

Deserializes an object state graph from its binary-serialized form that is contained in the specified Stream object.

Namespace:   System.Web.UI
Assembly:  System.Web (in System.Web.dll)

Public Function Deserialize (
	inputStream As Stream
) As Object

Parameters

inputStream
Type: System.IO.Stream

A Stream that the ObjectStateFormatter deserializes into an initialized object.

Return Value

Type: System.Object

An object that represents a deserialized object state graph.

Exception Condition
ArgumentNullException

The specified inputStream is null.

ArgumentException

An exception occurs during deserialization of the Stream. The exception message is appended to the message of the ArgumentException.

Any object state graph that is serialized with the Serialize method can be deserialized with the Deserialize method. The Deserialize(Stream) method is used to restore an object state graph stored in a Stream, such as a FileStream.

System_CAPS_security Security Note

Calling this method with untrusted data is a security risk. Call this method only with trusted data. For more information, see Untrusted Data Security Risks.

The following code example demonstrates how a class that derives from the PageStatePersister class initializes the ViewState collection. In this example, the ViewState collection has been assigned to the First field of a Pair object, and serialized to a file using the ObjectStateFormatter class. When the Load method is called, the Deserialize(Stream) method is used to deserialize view state from the file, and the ViewState property is initialized. This code example is part of a larger example provided for the PageStatePersister class.

'
' Load ViewState and ControlState.
'
Public Overrides Sub Load()

    Dim stateStream As Stream
    stateStream = GetSecureStream()

    ' Read the state string, using the StateFormatter.
    Dim reader As New StreamReader(stateStream)

    Dim serializedStatePair As String
    serializedStatePair = reader.ReadToEnd
    Dim statePair As Pair

    Dim formatter As IStateFormatter
    formatter = Me.StateFormatter

    ' Deserilize returns the Pair object that is serialized in
    ' the Save method.      
    statePair = CType(formatter.Deserialize(serializedStatePair), Pair)

    ViewState = statePair.First
    ControlState = statePair.Second
    reader.Close()
    stateStream.Close()
End Sub ' Load

.NET Framework
Available since 2.0
Return to top
Show: