SerializerProvider.CreateSerializerWriter Method

Initializes an object derived from the abstract SerializerWriter class for the specified Stream that will use the specified descriptor.

Namespace: System.Windows.Documents.Serialization
Assembly: PresentationFramework (in presentationframework.dll)

public SerializerWriter CreateSerializerWriter (
	SerializerDescriptor serializerDescriptor,
	Stream stream
public SerializerWriter CreateSerializerWriter (
	SerializerDescriptor serializerDescriptor, 
	Stream stream
public function CreateSerializerWriter (
	serializerDescriptor : SerializerDescriptor, 
	stream : Stream
) : SerializerWriter
You cannot use methods in XAML.



A SerializerDescriptor that contains serialization information for the SerializerWriter.


The Stream to which the returned object writes.

Return Value

An object of a class derived from SerializerWriter.

Exception typeCondition


One of the parameters is null.


The serializerDescriptor is specifying the wrong version.


It is not registered.


The assembly file cannot be found.


The assembly cannot be loaded.

Only fully trusted applications can call CreateSerializerWriter.

The following example shows using CreateSerializerWriter to return a plug-in serialization writer for saving a file. For the complete sample, see Document Serialization Sample.

// Create a SerializerProvider for accessing plug-in serializers.
SerializerProvider serializerProvider = new SerializerProvider();

// Locate the serializer that matches the fileName extension.
SerializerDescriptor selectedPlugIn = null;
foreach ( SerializerDescriptor serializerDescriptor in
                serializerProvider.InstalledSerializers )
    if ( serializerDescriptor.IsLoadable &&
         fileName.EndsWith(serializerDescriptor.DefaultFileExtension) )
    {   // The plug-in serializer and fileName extensions match.
        selectedPlugIn = serializerDescriptor;
        break; // foreach

// If a match for a plug-in serializer was found,
// use it to output and store the document.
if (selectedPlugIn != null)
    Stream package = File.Create(fileName);
    SerializerWriter serializerWriter =
    IDocumentPaginatorSource idoc =
        flowDocument as IDocumentPaginatorSource;
    serializerWriter.Write(idoc.DocumentPaginator, null);
    return true;

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0

Community Additions