XmlSerializer.Serialize Method (Stream, 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 Stream that references the specified namespaces.
Assembly: System.Xml.Serialization (in System.Xml.Serialization.dll)
Parameters
- stream
- Type: System.IO.Stream
The Stream used to write the XML document.
- o
- Type: System.Object
The Object to serialize.
- namespaces
- Type: System.Xml.Serialization.XmlSerializerNamespaces
The XmlSerializerNamespaces referenced by the object.
| Exception | Condition |
|---|---|
| InvalidOperationException | An error occurred during serialization. The original exception is available using the InnerException property. |
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 stream parameter to specify an object that derives from the abstract Stream class, which is designed to write to streams. Classes that derive from the Stream class include:
Note: |
|---|
The XmlSerializer cannot serialize arrays of List<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.
Note: