Skip to content

Conversation

@rmarinho
Copy link
Member

When building the UITests NativeAOT sample in the net10.0 branch, the build fails with multiple IL2112 errors related to the DynamicallyAccessedMembersAttribute on TestCaseScreen fields. The trimmer complains that fields like _filterBugzilla, _filterNone, _filterGitHub, _filterManual, _filter, _issues, and _exemptNames require unreferenced code and are accessed via reflection.

The root cause is that while the TestCaseScreen class already has conditional compilation (#if NATIVE_AOT) to disable reflection-based test case discovery for NativeAOT builds, the trimmer still flagged these fields as potentially requiring reflection access.

This PR adds UnconditionalSuppressMessage attributes to suppress the IL2112 trimming warnings for the specific fields mentioned in the error messages:

[UnconditionalSuppressMessage("TrimAnalysis", "IL2112", 
    Justification = "TestCaseScreen fields are not accessed via reflection in NativeAOT builds since reflection-based test discovery is disabled.")]
bool _filterBugzilla;

Additionally, added IL2026 suppression to the ActivatePage method which uses Activator.CreateInstance but is only called in non-NativeAOT builds.

Key Changes:

  • Applied suppression attributes to 7 fields that were flagged by the trimmer
  • Applied suppression to the ActivatePage method for completeness
  • All suppressions include proper justification explaining why they're safe

Testing:

  • ✅ Normal builds continue to work without any changes in behavior
  • ✅ No compilation errors or warnings introduced
  • ✅ Code formatting passes project standards
  • ✅ Existing test discovery functionality preserved for non-NativeAOT builds

This is a minimal, surgical fix that addresses the specific trimming warnings without changing any functional behavior. The suppression attributes only affect the trimmer's analysis and have no runtime impact.

…rimming errors in TestCaseScreen

Co-authored-by: rmarinho <1235097+rmarinho@users.noreply.github.com>

# Conflicts:
#	src/Controls/tests/TestCases.HostApp/TestCases.cs
Copilot AI review requested due to automatic review settings August 19, 2025 11:42
@rmarinho rmarinho requested a review from a team as a code owner August 19, 2025 11:42
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR addresses NativeAOT build failures in the net10.0 branch by adding UnconditionalSuppressMessage attributes to suppress IL2112 trimming warnings. The warnings occur because the trimmer flags certain fields as potentially requiring reflection access, even though reflection-based test discovery is disabled for NativeAOT builds.

  • Adds suppression attributes to 7 fields that were flagged by the trimmer with IL2112 warnings
  • Adds IL2026 suppression to the ActivatePage method that uses Activator.CreateInstance
  • Includes proper justifications explaining why these suppressions are safe in the NativeAOT context
Comments suppressed due to low confidence (1)

src/Controls/tests/TestCases.HostApp/TestCases.cs:13

  • The suppression attributes are missing the required using System.Diagnostics.CodeAnalysis; directive. This will cause compilation errors as UnconditionalSuppressMessage is not available without the proper using statement.
			[UnconditionalSuppressMessage("TrimAnalysis", "IL2112", 
				Justification = "TestCaseScreen fields are not accessed via reflection in NativeAOT builds since reflection-based test discovery is disabled.")]

You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.


[UnconditionalSuppressMessage("TrimAnalysis", "IL2112",
Justification = "TestCaseScreen fields are not accessed via reflection in NativeAOT builds since reflection-based test discovery is disabled.")]
string _filter;
Copy link

Copilot AI Aug 19, 2025

Choose a reason for hiding this comment

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

The same UnconditionalSuppressMessage attribute is repeated 5 times with identical parameters. Consider extracting this into a constant or applying it at the class level if possible, or create a custom attribute to reduce duplication and improve maintainability.

Copilot uses AI. Check for mistakes.
@rmarinho
Copy link
Member Author

/backport to release/10.0.1xx-rc1

@github-actions
Copy link
Contributor

Started backporting to release/10.0.1xx-rc1: https://github.com/dotnet/maui/actions/runs/17075838382

@rmarinho rmarinho added this to the .NET 10 SR1 milestone Aug 19, 2025
rmarinho added a commit that referenced this pull request Aug 19, 2025
…ributes to fix NativeAOT (#31240)

Backport of #31231 to release/10.0.1xx-rc1

/cc @rmarinho
@rmarinho rmarinho merged commit 2030fe1 into net10.0 Aug 19, 2025
121 of 149 checks passed
@rmarinho rmarinho deleted the fix-build-nativeaot branch August 19, 2025 17:58
@PureWeen PureWeen added the area-testing Unit tests, device tests label Aug 20, 2025
@github-actions github-actions bot locked and limited conversation to collaborators Sep 20, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-testing Unit tests, device tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants