Serializes and deserializes an instance of a type into XML stream or document using the supplied .NET Framework types. This class cannot be inherited.
Assembly: System.Runtime.Serialization (in System.Runtime.Serialization.dll)
The differs from the DataContractSerializer in one important way: the includes CLR type information in the serialized XML, whereas the DataContractSerializer does not. Therefore, the can be used only if both the serializing and deserializing ends share the same CLR types.
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."
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 . The DataContractAttribute attribute is applied to the class, and the DataMemberAttribute is applied to members (including a private member) to instruct the what to serialize.
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.