Skip to content

Fix Invalid Trim Warning Suppression in BindConverter.cs#66997

Open
surya3655 wants to merge 2 commits into
dotnet:mainfrom
surya3655:57016-fix-invalid-trim-warning
Open

Fix Invalid Trim Warning Suppression in BindConverter.cs#66997
surya3655 wants to merge 2 commits into
dotnet:mainfrom
surya3655:57016-fix-invalid-trim-warning

Conversation

@surya3655
Copy link
Copy Markdown

Fix Invalid Trim Warning Suppression in BindConverter.cs

Description

Fixed invalid UnconditionalSuppressMessage attributes on BindConverter.cs that were causing incorrect trimmer behavior. The original blanket suppressions on 130-line methods claimed "methods don't have DynamicallyAccessedMembers annotations" which was factually incorrect. Extracted reflection operations into small helper methods with targeted suppressions and accurate justifications.

Problem Description

The original code had blanket suppressions on large Get<T>() methods (130+ lines) that claimed:

"methods don't have DynamicallyAccessedMembers annotations"

This was false. Methods like MakeArrayTypeConverter<T> DO have [DynamicallyAccessedMembers(All)] annotations. The incorrect suppressions caused the trimmer to make wrong decisions about what to keep/remove, potentially breaking:

  • Array binding (e.g., string[], int[])
  • Enum binding
  • Nullable enum binding

Solution

Extracted reflection operations into small targeted helper methods with precise suppressions:

Helper Method Suppressions Justification
CreateArrayFormatter<T> IL2060, IL2076, IL3050 "MakeArrayFormatter has DynamicallyAccessedMembers(All) constraint"
CreateEnumParser<T> IL2060, IL3050 "ConvertToEnum has DynamicallyAccessedMembers(All) constraint"
CreateNullableEnumParser<T> IL2060, IL2071, IL3050 "innerType is verified to be an enum at runtime"
CreateArrayParser<T> IL2060, IL2076, IL3050 "Element type is validated at runtime"

Files Changed

File Change Type
src/Components/Components/src/BindConverter.cs Modified - Removed invalid blanket suppressions, added targeted suppressions
src/Components/Components/src/PersistentComponentState.cs Modified - Added IL3050 suppressions for JSON serialization
src/Components/Components/src/PersistentValueProviderComponentSubscription.cs Modified - Added IL3050 suppression for MakeGenericType

Validation

Test Result
Build with <EnableAOTAnalyzer>true ✅ 0 warnings, 0 errors
BindConverter unit tests (28 tests) ✅ All passed
All Components tests (1256 tests) ✅ All passed

Fixes : #57016

@surya3655 surya3655 requested a review from a team as a code owner June 3, 2026 09:49
@github-actions github-actions Bot added the area-blazor Includes: Blazor, Razor Components label Jun 3, 2026
@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Jun 3, 2026
@dotnet-policy-service
Copy link
Copy Markdown
Contributor

Thanks for your PR, @surya3655. Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

@surya3655
Copy link
Copy Markdown
Author

@dotnet-policy-service agree company="Syncfusion, Inc."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-blazor Includes: Blazor, Razor Components community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Invalid trim warning suppression in BindConverter

1 participant