Skip to content
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 2 commits into from
Sep 13, 2024

Conversation

sbomer
Copy link
Member

@sbomer sbomer commented Sep 11, 2024

Fixes #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. But I believe this is better than the currently available alternatives (annotating IXmlSerializable or the current unactionable warnings).

If folks are on board with this approach, I'll make a corresponding SDK change to add the RuntimeHostConfigurationOption.

Copy link
Member

@MichalStrehovsky MichalStrehovsky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM from trimming perspective.

@@ -14,6 +14,7 @@ configurations but their defaults might vary as any SDK can set the defaults dif
| VerifyDependencyInjectionOpenGenericServiceTrimmability | Microsoft.Extensions.DependencyInjection.VerifyOpenGenericServiceTrimmability | When set to true, DependencyInjection will verify trimming annotations applied to open generic services are correct. |
| _AggressiveAttributeTrimming | System.AggressiveAttributeTrimming | When set to true, aggressively trims attributes to allow for the most size savings possible, even if it could result in runtime behavior changes |
| _ComObjectDescriptorSupport | System.ComponentModel.TypeDescriptor.IsComObjectDescriptorSupported | When set to true, supports creating a TypeDescriptor based view of COM objects. |
| _DataSetXmlSerializationSupport | System.Data.DataSet.XmlSerializationSupport | When set to false, DataSet implementation of IXmlSerializable will throw instead of using trim-incompatible XML serialization. |
Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

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.)

Copy link
Member Author

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?

Copy link
Member

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.

Copy link
Member Author

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.

@sbomer sbomer merged commit 3e5d080 into dotnet:main Sep 13, 2024
106 of 110 checks passed
jtschuster pushed a commit to jtschuster/runtime that referenced this pull request Sep 17, 2024
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).
sbomer added a commit to dotnet/sdk that referenced this pull request Sep 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unactionable trim warnings when using DataSet and IXmlSerializable
3 participants