System.Runtime.Serialization 4.0.0.0 System.Runtime.Serialization.XmlObjectSerializer System.Runtime.Serialization.IFormatter

The differs from the in one important way: the includes CLR type information in the serialized XML, whereas the does not. Therefore, the can be used only if both the serializing and deserializing ends share the same CLR types.

The serializer can serialize types to which either the or attribute has been applied. It also serializes types that implement .

For more information about serialization, see Using Stand-alone Serialization.

## Incompatibility with XElement

The class is used to write XML. However, the NetDataContractSerializer cannot serialize an instance of the type. The following code, therefore, fails with the exception: "Root type 'System.Xml.Linq.XElement' is not supported at the top level by NetDataContractSerializer since it is IXmlSerializable with IsAny=true and must write all its contents including the root element."

code reference: NetDataContractSerializer#15

However, if an XElement is used as the type of a field or property of a class, the data contained by the field or property is serialized. This is because as a member of a class, the data is not the top level of the class.

Serializes and deserializes an instance of a type into XML stream or document using the supplied dnprdnshort types. This class cannot be inherited.

- Constructor
  4.0.0.0
  To be added.

  Initializes a new instance of the class.

- Constructor
  4.0.0.0

  The class allows you to pass in user-specific context data to use while reading and writing objects.

  Initializes a new instance of the class with the supplied streaming context data.

  A that contains context data.
- Constructor
  4.0.0.0
  To be added.

  Initializes a new instance of the class with the supplied XML root element and namespace.

  The name of the XML element that encloses the content to serialize or deserialize.
  The namespace of the XML element that encloses the content to serialize or deserialize.
- Constructor
  4.0.0.0

  The can be used to optimize performance when the same set of strings is used across object instances.

  Initializes a new instance of the class with two parameters of type that contain the root element and namespace used to specify the content.

  An that contains the name of the XML element that encloses the content to serialize or deserialize.
  An that contains the namespace of the XML element that encloses the content to serialize or deserialize.
- Constructor
  4.0.0.0
  To be added.

  The parameter is used when the interface is implemented in the class that is being serialized or deserialized.

  Initializes a new instance of the class with the supplied context data; in addition, specifies the maximum number of items in the object to be serialized, and parameters to specify whether extra data is ignored, the assembly loading method, and a surrogate selector.

  A that contains context data.
  The maximum number of items in the graph to serialize or deserialize.
  A enumeration value that specifies a method for locating and loading assemblies.
  An implementation of the .
- Constructor
  4.0.0.0
  To be added.

  The parameter is used when the interface is implemented in the class that is being serialized or deserialized.

  Initializes a new instance of the class with the supplied context data and root name and namespace; in addition, specifies the maximum number of items in the object to be serialized, and parameters to specify whether extra data is ignored, the assembly loading method, and a surrogate selector.

  The name of the XML element that encloses the content to serialize or deserialize.
  The namespace of the XML element that encloses the content to serialize or deserialize.
  A that contains context data.
  The maximum number of items in the graph to serialize or deserialize.
  A enumeration value that specifies a method for locating and loading assemblies.
  An implementation of the to handle the legacy type.
- Constructor
  4.0.0.0
  To be added.

  The can be used to optimize performance when the same set of strings is used across object instances.

  The parameter is used when the interface is implemented in the class that is being serialized or deserialized.

  Initializes a new instance of the class with the supplied context data, and root name and namespace (as parameters); in addition, specifies the maximum number of items in the object to be serialized, and parameters to specify whether extra data found is ignored, assembly loading method, and a surrogate selector.

  An that contains the root element of the content.
  An that contains the namespace of the root element.
  A that contains context data.
  The maximum number of items in the graph to serialize or deserialize.
  A enumeration value that specifies a method for locating and loading assemblies.
  An implementation of the to handle the legacy type.
- Property
  4.0.0.0
  System.Runtime.Serialization.Formatters.FormatterAssemblyStyle To be added.

  An AssemblyFormat instance can have two styles: or . Specifying Simple allows types in one version to be loaded and deserialized from an instance serialized from a different version.

  Gets a value that specifies a method for locating and loading assemblies.

- Property
  4.0.0.0
  System.Runtime.Serialization.SerializationBinder To be added.

  During serialization, a formatter transmits the information required to create an instance of an object of the correct type and version. This information generally includes the full type name and assembly name of the object. The assembly name includes the name, version, and strong name hash of the assembly. By default, deserialization uses this information to create an instance of an identical object (with the exception of any assembly loading restricted by the security policy). Some users need to control which class to load, either because the class has moved between assemblies or a different version of the class is required on the server and client.

  Gets or sets an object that controls class loading.

- Property
  4.0.0.0
  System.Runtime.Serialization.StreamingContext To be added. To be added.

  Gets or sets the object that enables the passing of context data that is useful while serializing or deserializing.

- Method
  4.0.0.0
  System.Object ``

  This method assumes the default format is text XML.

  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.

  Deserializes an XML document or stream into an object.

  The deserialized object.

  A that contains the XML to deserialize.
- Property
  4.0.0.0
  System.Boolean To be added.

  When implementing the , data from a future version of a type can be stored by the . During a round trip (where an object is deserialized, altered, and serialized again), the extra data is stored and serialized again. For more information, see Serialization and Deserialization.

  Gets a value that specifies whether data supplied by an extension of the object is ignored.

- Method
  4.0.0.0
  System.Boolean ``

  The 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 and values passed into the constructor (if present).

  You can set the and in the following constructors: , , and .

  Determines whether the is positioned on an object that can be deserialized using the specified reader.

  true, if the reader is at the start element of the stream to read; otherwise, false.

  An that contains the XML to read.
- Property
  4.0.0.0
  System.Int32 To be added.

  For more information about setting quotas, see Security Considerations for Data.

  Gets the maximum number of items allowed in the object to be serialized.

- Method
  4.0.0.0
  System.Object `` `` To be added.

  The 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 and values passed into the constructor (if present).

  You can set the and in the following constructors: , , and .

  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.

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

  The deserialized object.

  The used to read the XML stream or document.
- Method
  4.0.0.0
  System.Void `` `` To be added.

  Serializes the specified object graph using the specified writer.

  The to serialize with. The object to serialize. All child objects of this root object are automatically serialized.
- Property
  4.0.0.0
  System.Runtime.Serialization.ISurrogateSelector To be added.

  For more information about the , see Data Contract Surrogates.

  Gets or sets an object that assists the formatter when selecting a surrogate for serialization.

- Method
  4.0.0.0
  System.Void `` To be added.

  Writes the closing XML element using an .

  The used to write the XML document or stream.
- Method
  4.0.0.0
  System.Void `` `` To be added.

  Writes the XML content using an .

  The used to write the XML content. The object to serialize. All child objects of this root object are automatically serialized.
- Method
  4.0.0.0
  System.Void `` `` To be added.

  Writes the opening XML element using an .

  The used to write the XML element. The object to serialize. All child objects of this root object are automatically serialized.