Export (0) Print
Expand All

XmlSerializer.Serialize Method (XmlWriter, Object)

Serializes the specified Object and writes the XML document to a file using the specified XmlWriter.

Namespace:  System.Xml.Serialization
Assembly:  System.Xml.Serialization (in System.Xml.Serialization.dll)

public void Serialize(
	XmlWriter xmlWriter,
	Object o
)

Parameters

xmlWriter
Type: System.Xml.XmlWriter
The XmlWriter used to write the XML document.
o
Type: System.Object
The Object to serialize.

ExceptionCondition
InvalidOperationException

An error occurred during serialization. The original exception is available using the InnerException property.

The Serialize method converts the public fields and read/write properties of an object into XML. It does not convert methods, indexers, private fields, or read-only properties. To serialize all an object's fields and properties, both public and private, use the BinaryFormatter.

In the xmlWriter parameter, specify an object that derives from the abstract XmlWriter class. The XmlTextWriter derives from the XmlWriter.

NoteNote:

The XmlSerializer cannot serialize arrays of ArrayList and arrays of List<T>.

Platform Notes

Silverlight for Windows Phone Silverlight for Windows Phone

 The XmlSerializer.Serialize method throws an InvalidOperationException if the XmlSerializer object is initialized with a type parameter that contains an array of objects of type XElement.

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Community Additions

ADD
Show:
© 2015 Microsoft