-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Obsolete SerializationFormat.Binary in DataTable/DataSet and put it behind an appcontext switch #39289
Comments
Tagging subscribers to this area: @roji, @ajcvickers |
What should the behaviour be if a user attempts to use binary serialization once the code to allow it has been removed? silent no-op or throwing of an exception? If an exception there is already an invalid enum value exception (I think ArgumentException) present which could be thrown or should there be a new one indicating that it has been removed? Should SerializationFormat.Binary be marked as obsolete? Should any exceptions in System.Data.Common have their serialization/deserialization methods marked as obsolete while this work is being done? |
From offline conversations the most straightforward way to do this would be to mark the |
@GrabYourPitchforks would we want to reuse the same diagnostic id as binary formatter’s obsoletion ( |
@jeffhandley I don't think so. There are two issues at play here. The first issue (as tracked here) is the removal of The second issue (tracked by dotnet/designs#141) is the eventual removal of Note: I should clarify a possible point of confusion. The |
Can someone clarify this? This statement seems to suggest that if (remotingFormat != SerializationFormat.Xml)
{
use BF to serialize. Nothing here suggests XML unless I'm missing something?
}
else
{
// old behaviour
string strSchema = GetXmlSchemaForRemoting(null);
string? strData = null;
info.AddValue(KEY_XMLSCHEMA, strSchema);
StringBuilder strBuilder = new StringBuilder(EstimatedXmlStringSize() * 2);
StringWriter strWriter = new StringWriter(strBuilder, CultureInfo.InvariantCulture);
XmlTextWriter w = new XmlTextWriter(strWriter);
WriteXml(w, XmlWriteMode.DiffGram);
strData = strWriter.ToString();
info.AddValue(KEY_XMLDIFFGRAM, strData);
} It looks like |
The default value is var dt = new DataTable(/* ... */) { RemotingFormat = RemotingFormat.Xml };
var bf = new BinaryFormatter(/* ... */);
bf.Serialize(memStream, dt); The container (DataTable) is written using a BinaryFormatter-serialized format, because the caller instantiated a BinaryFormatter and passed a DataTable to it. But under the covers, DataTable is really XML-serializing its internal values and writing a bunch of XML literal strings to the underlying formatter. If you look at the raw payload bytes, it basically looks like the payload says "Hi, I'm a BinaryFormatter-serialized DataTable, and I have a bunch of string members!" It's akin to BinaryFormatter-serializing the following pseudo-code: [Serializable]
public class MyDataTable
{
public string ColumnName1;
public Type ColumnType1;
public string ColumnValue1SerializedAsXml;
public string ColumnName2;
public Type ColumnType2;
public string ColumnValue2SerializedAsXml;
/* ... */
} If you instead set [Serializable]
public class MyDataTable
{
public string ColumnName1;
public Type ColumnType1;
public byte[] ColumnValue1SerializedAsBinaryFormatter; // note: raw bytes instead of string
public string ColumnName2;
public Type ColumnType2;
public byte[] ColumnValue2SerializedAsBinaryFormatter; // note: raw bytes instead of string
/* ... */
} When serializing, DataTable also inserts a marker specifying which RemotingFormat was in use, that way it can call back into the correct code paths during deserialization. If the incoming payload contains the The suggestion here is to dishonor the |
Submitted #65139 to obsolete SerializationFormat.Binary and put it behind an appcontext switch, for .NET 7.0. #65140 tracks removing the logic entirely in .NET 8.0. Additional tasks:
@GrabYourPitchforks let me know if this all looks OK and if there's anything I've missed. |
@roji Obsoleting |
@gewarren thanks - opened dotnet/docs#28726. Can you point me to where I'd add some docs on the DataSet and DataTable security guidance page? |
You can edit that file here: https://github.com/dotnet/docs/blob/main/docs/framework/data/adonet/dataset-datatable-dataview/security-guidance.md. There's a section titled "Deserialize a DataSet or DataTable via BinaryFormatter". |
Tracking the remaining docs work on my list, will do that as coding work winds down on 7.0. |
Ref:
runtime/src/libraries/System.Data.Common/src/System/Data/DataSet.cs
Lines 303 to 310 in af828ae
runtime/src/libraries/System.Data.Common/src/System/Data/DataSet.cs
Lines 378 to 387 in af828ae
This issue tracks the removal of this code per the
BinaryFormatter
obsoletion plan.From offline discussions with Arthur and friends, we may want to eliminate support for
SerializationFormat.Binary
anyway, since it's not compatible between .NET Framework and .NET Core / .NET 5.0+. The only data format compatible between the different runtimes isSerializationFormat.Xml
.The text was updated successfully, but these errors were encountered: