[net10.0] Add UnconditionalSuppressMessage attributes to fix NativeAOT#31231
[net10.0] Add UnconditionalSuppressMessage attributes to fix NativeAOT#31231
Conversation
…rimming errors in TestCaseScreen Co-authored-by: rmarinho <1235097+rmarinho@users.noreply.github.com> # Conflicts: # src/Controls/tests/TestCases.HostApp/TestCases.cs
There was a problem hiding this comment.
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
ActivatePagemethod that usesActivator.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 asUnconditionalSuppressMessageis 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; |
There was a problem hiding this comment.
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.
|
/backport to release/10.0.1xx-rc1 |
|
Started backporting to release/10.0.1xx-rc1: https://github.com/dotnet/maui/actions/runs/17075838382 |
When building the UITests NativeAOT sample in the net10.0 branch, the build fails with multiple IL2112 errors related to the
DynamicallyAccessedMembersAttributeonTestCaseScreenfields. The trimmer complains that fields like_filterBugzilla,_filterNone,_filterGitHub,_filterManual,_filter,_issues, and_exemptNamesrequire unreferenced code and are accessed via reflection.The root cause is that while the
TestCaseScreenclass 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
UnconditionalSuppressMessageattributes to suppress the IL2112 trimming warnings for the specific fields mentioned in the error messages:Additionally, added IL2026 suppression to the
ActivatePagemethod which usesActivator.CreateInstancebut is only called in non-NativeAOT builds.Key Changes:
ActivatePagemethod for completenessTesting:
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.