NetDataContractSerializer Class

Serializes and deserializes an instance of a type into XML stream or document using the supplied .NET Framework types. This class cannot be inherited.

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

public final class NetDataContractSerializer extends XmlObjectSerializer implements IFormatter

The NetDataContractSerializer differs from the DataContractSerializer in one important way: the NetDataContractSerializer includes CLR type information in the serialized XML, whereas the DataContractSerializer does not. Therefore, the NetDataContractSerializer can be used only if both the serializing and deserializing ends share the same CLR types.

The serializer can serialize types to which either the DataContractAttribute or SerializableAttribute attribute has been applied. It also serializes types that implement ISerializable.

For more information about serialization, see Using Stand-alone Serialization.

Incompatibility with XElement

The XElement class is used to write XML. However, the NetDataContractSerializer cannot serialize an instance of the type. The following code, therefore, fails with the exception: "Root type 'System.Xml.Linq.XElement' is not supported at the top level by NetDataContractSerializer since it is IXmlSerializable with IsAny=true and must write all its contents including the root element."

No code example is currently available or this language may not be supported.

However, if an XElement is used as the type of a field or property of a class, the data contained by the field or property is serialized. This is because as a member of a class, the data is not the top level of the class.

The following example code shows a type named Person that is serialized by the NetDataContractSerializer. The DataContractAttribute attribute is applied to the class, and the DataMemberAttribute is applied to members (including a private member) to instruct the NetDataContractSerializer what to serialize.

No code example is currently available or this language may not be supported.

System.Object
  System.Runtime.Serialization.XmlObjectSerializer
    System.Runtime.Serialization.NetDataContractSerializer

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft