-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Add feature switch to disable DataSet XML serialization #107713
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have some process to decide if something is a public or non-public switch? The "has been disabled in the app configuration" in the exception message sounds like something that we might want to leave configurable. If someone turns it on, my understanding is they'll get trimming warnings, so it should be fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's true that there will be trim warnings if someone turns it on. I made this one non-public because I don't think there's much value in toggling it in a non-trimmed app - it feels more like a behavior that should be automatically disabled when trimming, but is otherwise not super interesting.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My question is more whether someone could have been using it with TrimMode=partial and wants to re-enable it. (My assumption is that this doesn't reflect on our IsTrimmable assemblies, but on user code.)
We do document BuiltInComInteropSupport and enabling that one is a lot more scarier. (I always wondered why we did that.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would consider that an unsupported scenario where we provide an undocumented escape hatch - in that case I think it's fine for the escape hatch to be non-public. Maybe BuiltInComInteropSupport should have been non-public too.
Curious what you think - should it be public? Or should the exception message say something else?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm questioning this because this might be the first feature switch PR that I'm tagged on adding a non-public switch. We have others that feel in the same category and are not underscored (
JsonSerializerIsReflectionEnabledByDefault
comes to mind). Enabling them with full trimming will likely break the app but the story might be different with partial trimming.It comes down to whether we would consider this supported with partial trimming (to the extent that we say it's supported for JsonSerializerIsReflectionEnabledByDefault, EnableCppCLIHostActivation, EnableUnsafeBinaryFormatterInDesigntimeLicenseContextSerialization, etc.).
dotnet/docs#41739 (comment) touched on that a bit but I think we'll want to have some better guidelines around this.
I don't feel strongly however. I'm not a fan of warning-disabled partial trimming, but we have appmodels that still set it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for bringing it up - I think it warrants further discussion. I left some thoughts in dotnet/docs#41739 (comment).
I'll leave this one non-public here per my comments, but if we reach a different agreement in that discussion I'll go back and make it public.