Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

XmlSerializer.Serialize Method (Stream, Object, XmlSerializerNamespaces)

Serializes the specified Object and writes the XML document to a file using the specified Stream that references the specified namespaces.

Namespace:  System.Xml.Serialization
Assembly:  System.Xml.Serialization (in System.Xml.Serialization.dll)
public void Serialize(
	Stream stream,
	Object o,
	XmlSerializerNamespaces namespaces
)

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.
ExceptionCondition
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. To serialize all fields and properties, both public and private, use the BinaryFormatter.

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:

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.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.