forked from dotnet/runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add feature switch to disable DataSet XML serialization (dotnet#107713)
Fixes dotnet#107704 by introducing a feature switch that makes the DataSet and DataTable implementation of IXmlSerializable throw. This prevents unactionable warnings from the DataSet/DataTable implementation details when both DataSet and IXmlSerializable happen to be used in an app. The downside of this approach is that the trim warnings are replaced by a runtime failure. The advantage is that it eliminates unactionable warnings. It is preferable over annotating IXmlSerializable methods because that interface is not inherently trim-incompatible (some implementations might be compatible).
- Loading branch information
Showing
7 changed files
with
128 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
src/libraries/System.Data.Common/tests/TrimmingTests/DataSetXmlSerialization.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System; | ||
using System.Data; | ||
using System.Xml.Schema; | ||
using System.Xml.Serialization; | ||
|
||
namespace DataSetXmlSerializationTrimmingTests | ||
{ | ||
class Program | ||
{ | ||
static int Main(string[] args) | ||
{ | ||
IXmlSerializable xmlSerializable = new DataSet(); | ||
|
||
// Calling GetSchema should throw NotSupportedException | ||
try | ||
{ | ||
xmlSerializable.GetSchema(); | ||
return -1; | ||
} | ||
catch (NotSupportedException) | ||
{ | ||
} | ||
|
||
// Calling ReadXml should throw NotSupportedException | ||
try | ||
{ | ||
xmlSerializable.ReadXml(null); | ||
return -2; | ||
} | ||
catch (NotSupportedException) | ||
{ | ||
} | ||
|
||
// Calling WriteXml should throw NotSupportedException | ||
try | ||
{ | ||
xmlSerializable.WriteXml(null); | ||
return -3; | ||
} | ||
catch (NotSupportedException) | ||
{ | ||
} | ||
|
||
xmlSerializable = new DataTable(); | ||
|
||
// Calling GetSchema should throw NotSupportedException | ||
try | ||
{ | ||
xmlSerializable.GetSchema(); | ||
return -4; | ||
} | ||
catch (NotSupportedException) | ||
{ | ||
} | ||
|
||
// Calling ReadXml should throw NotSupportedException | ||
try | ||
{ | ||
xmlSerializable.ReadXml(null); | ||
return -5; | ||
} | ||
catch (NotSupportedException) | ||
{ | ||
} | ||
|
||
// Calling WriteXml should throw NotSupportedException | ||
try | ||
{ | ||
xmlSerializable.WriteXml(null); | ||
return -6; | ||
} | ||
catch (NotSupportedException) | ||
{ | ||
} | ||
|
||
return 100; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters