Skip to content

Replace global analyzer suppressions with DynamicallyAccessedMembers attribute#47

Merged
Malcolmnixon merged 3 commits intomainfrom
copilot/resolve-yamldotnet-warnings
Jan 10, 2026
Merged

Replace global analyzer suppressions with DynamicallyAccessedMembers attribute#47
Malcolmnixon merged 3 commits intomainfrom
copilot/resolve-yamldotnet-warnings

Conversation

Copy link
Contributor

Copilot AI commented Jan 10, 2026

YamlDotNet deserializer DTOs triggered false positives from SonarAnalyzer (S3459: unassigned properties, S1144: unused setters) because the analyzer doesn't understand reflection-based property access.

Changes

  • Added [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)] to YamlDocument, YamlSection, YamlRequirement, and YamlMapping classes
  • Replaced global .globalconfig suppressions with targeted [SuppressMessage] attributes on each DTO class
  • Removed .globalconfig file entirely

Before

// .globalconfig suppressed S3459 and S1144 globally

private sealed class YamlDocument
{
    public List<YamlSection>? Sections { get; set; }
}

After

[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)]
[SuppressMessage("SonarAnalyzer.CSharp", "S3459:Unassigned members should be removed", 
    Justification = "Properties are set by YamlDotNet deserializer via reflection")]
[SuppressMessage("SonarAnalyzer.CSharp", "S1144:Unused private types or members should be removed", 
    Justification = "Properties are accessed by YamlDotNet deserializer via reflection")]
private sealed class YamlDocument
{
    public List<YamlSection>? Sections { get; set; }
}

The DynamicallyAccessedMembers attribute improves Native AOT/trimming support while targeted suppressions provide better maintainability than global rules.

Original prompt

This section details on the original issue you should resolve

<issue_title>[Feature]: Resolve YamlDotNet serialization warnings</issue_title>
<issue_description>### Problem Statement

Properties written by YamlDotNet deserialization are reported as unused because the static analyzer does not know about how YamlDotNet accesses them.

Proposed Solution

Consider using the [DynamicallyAccessedMembers] attribute rather than the .globalconfig disabling of warnings.

Alternatives Considered

No response

Additional Context

No response

Priority

None

Contribution

  • I would be willing to submit a PR for this feature

Code of Conduct

  • I agree to follow this project's Code of Conduct</issue_description>

Comments on the Issue (you are @copilot in this section)

Custom agent used: Software Quality Enforcer
Expert agent for code quality, testing standards, code reviews, security analysis, and ensuring adherence to coding conventions


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI self-assigned this Jan 10, 2026
Copilot AI and others added 2 commits January 10, 2026 06:16
…s for YamlDotNet DTOs

Co-authored-by: Malcolmnixon <1863707+Malcolmnixon@users.noreply.github.com>
Co-authored-by: Malcolmnixon <1863707+Malcolmnixon@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix YamlDotNet serialization warnings with attribute Replace global analyzer suppressions with DynamicallyAccessedMembers attribute Jan 10, 2026
Copilot AI requested a review from Malcolmnixon January 10, 2026 06:20
@Malcolmnixon Malcolmnixon marked this pull request as ready for review January 10, 2026 06:25
@Malcolmnixon Malcolmnixon merged commit fcfdebc into main Jan 10, 2026
13 checks passed
@Malcolmnixon Malcolmnixon deleted the copilot/resolve-yamldotnet-warnings branch January 10, 2026 06:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Resolve YamlDotNet serialization warnings

2 participants