SerializationFormat.Binary is obsolete
SerializationFormat.Binary is obsolete for DataTable and DataSet. Binary serialization relies on BinaryFormatter, which is insecure. If you use SerializationFormat.Binary in your code, obsoletion warning SYSLIB0038 will be generated at compile time.
In addition, an InvalidEnumArgumentException is thrown at run time if you:
- Set DataSet.RemotingFormat or DataTable.RemotingFormat to SerializationFormat.Binary.
- Call one of the deserialization constructors for DataTable or DataSet with binary data.
Previous behavior
Previously, DataTable and DataSet could be serialized and deserialized with their RemotingFormat property set to SerializationFormat.Binary, which used BinaryFormatter under the hood.
New behavior
Starting in .NET 7, if you attempt to serialize or deserialize DataTable and DataSet with their RemotingFormat property set to SerializationFormat.Binary, an InvalidEnumArgumentException is thrown.
Version introduced
.NET 7
Type of breaking change
This change can affect source compatibility and binary compatibility.
Reason for change
SerializationFormat.Binary is implemented via BinaryFormatter, which is insecure and being obsoleted across the entire .NET stack.
Recommended action
If your code uses SerializationFormat.Binary, switch to using SerializationFormat.Xml or use another method of serialization.
Otherwise, you can set the Switch.System.Data.AllowUnsafeSerializationFormatBinary
AppContext switch. This switch lets you opt in to allowing the use of SerializationFormat.Binary, so that code can work as before. However, this switch will be removed in .NET 8. For information about setting the switch, see AppContext for library consumers.
Affected APIs
- System.Data.SerializationFormat.Binary
- DataSet.RemotingFormat
- DataTable.RemotingFormat
- DataSet(SerializationInfo, StreamingContext)
- DataSet(SerializationInfo, StreamingContext, Boolean)
- DataTable(SerializationInfo, StreamingContext)