Skip to content

Annotate System.ServiceModel.Syndication for trimming and AOT #114028

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

reflectronic
Copy link
Contributor

@reflectronic reflectronic commented Mar 28, 2025

Despite the closeness of this library to XML and WCF, the reflection usage in this library is nicely cordoned off and mostly limited to convenience methods. Thus, the library is largely trimming-compatible.

Fixes #113990
Contributes to #75480

Copy link

Note regarding the new-api-needs-documentation label:

This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change.

Copy link

Note regarding the new-api-needs-documentation label:

This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change.

@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Mar 28, 2025
public SyndicationElementExtension(string outerName, string outerNamespace, object dataContractExtension)
: this(outerName, outerNamespace, dataContractExtension, null)
{
}

[RequiresUnreferencedCode(SyndicationFeedFormatter.RequiresUnreferencedCodeWarning)]
public SyndicationElementExtension(string outerName, string outerNamespace, object dataContractExtension, XmlObjectSerializer dataContractSerializer)
Copy link
Contributor Author

@reflectronic reflectronic Mar 28, 2025

Choose a reason for hiding this comment

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

DataContractSerializer's constructor isn't RequiresUnreferencedCode, but all of the methods on it are. This constructor just creates a DataContractSerializer without using it, so technically it doesn't need RequiresUnreferencedCode.

If you use this constructor, a bunch of other members on this class will use that DataContractSerializer. If you use the constructor taking XmlReader, they don't use any serializer and are perfectly trim-compatible.

So, I think it's better to leave the attribute on this constructor. Otherwise, all those members would need to be marked RequiresUnreferencedCode. This way, if you use the XmlReader constructor, you won't get warnings.

Does that make sense?

@@ -109,6 +118,8 @@ public string OuterName

public string OuterNamespace
{
[UnconditionalSuppressMessage("Trimming", "IL2026:RequiresUnreferencedCode", Justification = "Constructors not marked RequiresUnreferencedCode always set _outerName to a non-null value.")]
[UnconditionalSuppressMessage("AOT", "IL3050:RequiresDynamicCode", Justification = "Constructors not marked RequiresUnreferencedCode always set _outerName to a non-null value.")]
get
{
if (_outerName == null)
Copy link
Contributor Author

@reflectronic reflectronic Mar 28, 2025

Choose a reason for hiding this comment

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

Since this path is statically reachable, the linker will still keep around bits of XmlSerializer and DataContractSerializer, right? Is there something easy we can do about it?

Copy link
Contributor

Choose a reason for hiding this comment

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

You can split the ExtensionDataWriter nested class into a base abstract class (or interface) and a concrete implementation, and create the latter only in the trim-unsafe constructors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

IL2067 shown when publishing NativeAOT app with System.ServiceModel.Syndication in use
2 participants