NetDataContractSerializer Constructor (XmlDictionaryString, XmlDictionaryString, StreamingContext, Int32, Boolean, FormatterAssemblyStyle, ISurrogateSelector)


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

Initializes a new instance of the NetDataContractSerializer class with the supplied context data, and root name and namespace (as XmlDictionaryString parameters); in addition, specifies the maximum number of items in the object to be serialized, and parameters to specify whether extra data found is ignored, assembly loading method, and a surrogate selector.

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

Public Sub New (
	rootName As XmlDictionaryString,
	rootNamespace As XmlDictionaryString,
	context As StreamingContext,
	maxItemsInObjectGraph As Integer,
	ignoreExtensionDataObject As Boolean,
	assemblyFormat As FormatterAssemblyStyle,
	surrogateSelector As ISurrogateSelector


Type: System.Xml.XmlDictionaryString

An XmlDictionaryString that contains the root element of the content.

Type: System.Xml.XmlDictionaryString

An XmlDictionaryString that contains the namespace of the root element.

Type: System.Runtime.Serialization.StreamingContext

A StreamingContext that contains context data.

Type: System.Int32

The maximum number of items in the graph to serialize or deserialize.

Type: System.Boolean

true to ignore the data supplied by an extension of the type; otherwise, false.

Type: System.Runtime.Serialization.Formatters.FormatterAssemblyStyle

A FormatterAssemblyStyle enumeration value that specifies a method for locating and loading assemblies.

Type: System.Runtime.Serialization.ISurrogateSelector

An implementation of the IDataContractSurrogate to handle the legacy type.

Exception Condition

maxItemsInObjectGraph value is less than 0.

The XmlDictionaryString can be used to optimize performance when the same set of strings is used across object instances.

The ignoreExtensionDataObject parameter is used when the IExtensibleDataObject interface is implemented in the class that is being serialized or deserialized.

The following example creates an instance of the NetDataContractSerializer specifying the XML element name and namespace (as XmlDictionaryString arguments) to expect when deserializing. The code also sets the ignoreExtensionDataObject, and specifies an implementation of the ISurrogateSelector interface to handle to assist the serializer when selecting a surrogate (for deserializing legacy types).

Public Shared Sub Constructor7() 
    ' Create an instance of the StreamingContext to hold
    ' context data.
    Dim sc As New StreamingContext()

    ' Create an XmlDictionary and add values to it.
    Dim d As New XmlDictionary()
    Dim name_value As XmlDictionaryString =d.Add("Customer")
    Dim ns_value As XmlDictionaryString = d.Add("")

    ' Create an instance of a class that implements the 
    ' ISurrogateSelector interface. The implementation code
    ' is not shown here.
    Dim mySurrogateSelector As New MySelector()

    Dim ser As New System.Runtime.Serialization. _
      NetDataContractSerializer( _
      name_value, _
      ns_value, _
      sc, _
      65536, _
      True, _
      FormatterAssemblyStyle.Simple, _

    ' Other code not shown.    

End Sub 

.NET Framework
Available since 3.0
Return to top