Edit

Share via


NetDataContractSerializer.ReadObject Method

Definition

Reads the XML stream or document and returns the deserialized object.

Overloads

ReadObject(XmlReader)

Reads the XML stream or document with an XmlDictionaryReader and returns the deserialized object.

ReadObject(XmlDictionaryReader, Boolean)

Reads the XML stream or document with an XmlDictionaryReader and returns the deserialized object; also checks whether the object data conforms to the name and namespace used to create the serializer.

ReadObject(XmlReader, Boolean)

Reads the XML stream or document with an XmlDictionaryReader and returns the deserialized object; also checks whether the object data conforms to the name and namespace used to create the serializer.

Remarks

Important

Calling this method with untrusted data is a security risk. Call this method only with trusted data. For more information, see Validate All Inputs.

ReadObject(XmlReader)

Reads the XML stream or document with an XmlDictionaryReader and returns the deserialized object.

public:
 override System::Object ^ ReadObject(System::Xml::XmlReader ^ reader);
public override object ReadObject (System.Xml.XmlReader reader);
override this.ReadObject : System.Xml.XmlReader -> obj
Public Overrides Function ReadObject (reader As XmlReader) As Object

Parameters

reader
XmlReader

The XmlReader used to read the XML stream or document.

Returns

The deserialized object.

Exceptions

the reader is set to null.

Remarks

Important

Calling this method with untrusted data is a security risk. Call this method only with trusted data. For more information, see Validate All Inputs.

Applies to

ReadObject(XmlDictionaryReader, Boolean)

Reads the XML stream or document with an XmlDictionaryReader and returns the deserialized object; also checks whether the object data conforms to the name and namespace used to create the serializer.

public:
 override System::Object ^ ReadObject(System::Xml::XmlDictionaryReader ^ reader, bool verifyObjectName);
public override object ReadObject (System.Xml.XmlDictionaryReader reader, bool verifyObjectName);
override this.ReadObject : System.Xml.XmlDictionaryReader * bool -> obj
Public Overrides Function ReadObject (reader As XmlDictionaryReader, verifyObjectName As Boolean) As Object

Parameters

reader
XmlDictionaryReader

The XmlDictionaryReader used to read the XML stream or document.

verifyObjectName
Boolean

true to check whether the enclosing XML element name and namespace correspond to the root name and root namespace used to construct the serializer; false to skip the verification.

Returns

The deserialized object.

Exceptions

the reader is set to null.

Remarks

The verifyObjectName parameter determines whether it can read an object by examining the name and namespace of the XML element the reader is positioned at, and comparing the values to expected name and namespace. The expected name and namespace can be set with the following: the data contract name and namespace of the type passed into the constructor, or the rootName and rootNamespace values passed into the constructor (if present).

You can set the rootName and rootNamespace in the following constructors: NetDataContractSerializer(String, String), NetDataContractSerializer(XmlDictionaryString, XmlDictionaryString), and NetDataContractSerializer(XmlDictionaryString, XmlDictionaryString, StreamingContext, Int32, Boolean, FormatterAssemblyStyle, ISurrogateSelector).

Important

Calling this method with untrusted data is a security risk. Call this method only with trusted data. For more information, see Validate All Inputs.

Applies to

ReadObject(XmlReader, Boolean)

Reads the XML stream or document with an XmlDictionaryReader and returns the deserialized object; also checks whether the object data conforms to the name and namespace used to create the serializer.

public:
 override System::Object ^ ReadObject(System::Xml::XmlReader ^ reader, bool verifyObjectName);
public override object ReadObject (System.Xml.XmlReader reader, bool verifyObjectName);
override this.ReadObject : System.Xml.XmlReader * bool -> obj
Public Overrides Function ReadObject (reader As XmlReader, verifyObjectName As Boolean) As Object

Parameters

reader
XmlReader

The XmlReader used to read the XML stream or document.

verifyObjectName
Boolean

true to check whether the enclosing XML element name and namespace correspond to the root name and root namespace used to construct the serializer; false to skip the verification.

Returns

The deserialized object.

Exceptions

the reader is set to null.

Remarks

The verifyObjectName parameter determines whether it can read an object by examining the name and namespace of the XML element the reader is positioned at, and comparing the values to expected name and namespace. The expected name and namespace can be set with the following: the data contract name and namespace of the type passed into the constructor, or the rootName and rootNamespace values passed into the constructor (if present).

You can set the rootName and rootNamespace in the following constructors: NetDataContractSerializer(String, String), NetDataContractSerializer(XmlDictionaryString, XmlDictionaryString), and NetDataContractSerializer(XmlDictionaryString, XmlDictionaryString, StreamingContext, Int32, Boolean, FormatterAssemblyStyle, ISurrogateSelector).

Important

Calling this method with untrusted data is a security risk. Call this method only with trusted data. For more information, see Validate All Inputs.

Applies to