DataContractSerializer.ReadObject Method (XmlDictionaryReader, Boolean)

Reads the XML stream with an XmlDictionaryReader and returns the deserialized object, and also specifies whether a check is made to verify the object name before reading its value.

Namespace: System.Runtime.Serialization
Assembly: System.Runtime.Serialization (in system.runtime.serialization.dll)

public override Object ReadObject (
	XmlDictionaryReader reader,
	bool verifyObjectName
public Object ReadObject (
	XmlDictionaryReader reader, 
	boolean verifyObjectName
public override function ReadObject (
	reader : XmlDictionaryReader, 
	verifyObjectName : boolean
) : Object
Not applicable.



The XmlDictionaryReader used to read the XML stream.


true to check whether the name of the object corresponds to the root name value supplied in the constructor; otherwise, false.

Return Value

The deserialized object.

Exception typeCondition


if the verifyObjectName parameter is set to true, and the element name and namespace do not correspond to the values set in the constructor.

The following example reads an XML document and deserializes an instance of an object.

public static void ReadObject(string fileName)
    Console.WriteLine("Deserializing an instance of the object.");
    FileStream fs = new FileStream(fileName,
    XmlDictionaryReader reader =
        XmlDictionaryReader.CreateTextReader(fs, new XmlDictionaryReaderQuotas());
    DataContractSerializer ser = new DataContractSerializer(typeof(Person));

    // Deserialize the data and read it from the instance.
    Person deserializedPerson =
        (Person)ser.ReadObject(reader, true);
    Console.WriteLine(String.Format("{0} {1}, ID: {2}",
    deserializedPerson.FirstName, deserializedPerson.LastName,

Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0