XmlSerializer.Serialize Method (XmlWriter, Object)

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

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 Sub Serialize ( _
    xmlWriter As XmlWriter, _
    o As Object _
public void Serialize(
    XmlWriter xmlWriter,
    Object o



Exception Condition

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.

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


The XmlSerializer cannot serialize arrays of List<(Of <(T>)>).

Version Notes

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.

Version Information

Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0


Windows Phone

See Also


XmlSerializer Class

Serialize Overload

System.Xml.Serialization Namespace