XmlSerializer.Serialize Method (TextWriter, Object, XmlSerializerNamespaces)

[ 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 TextWriter and references the specified namespaces.

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

Syntax

Public Sub Serialize ( _
    textWriter As TextWriter, _
    o As Object, _
    namespaces As XmlSerializerNamespaces _
)
public void Serialize(
    TextWriter textWriter,
    Object o,
    XmlSerializerNamespaces namespaces
)

Parameters

Exceptions

Exception Condition
InvalidOperationException

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

Remarks

When the Serialize method is invoked the public fields and read/write properties of an object are converted into XML. Methods, indexers, private fields, and read-only properties are not serialized.

Use the textWriter parameter to specify an object that derives from the abstract TextWriter class. Classes that derive from TextWriter class include:

Note

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

Platforms

Windows Phone

See Also

Reference

XmlSerializer Class

Serialize Overload

System.Xml.Serialization Namespace