-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Open
Labels
area-blazorIncludes: Blazor, Razor ComponentsIncludes: Blazor, Razor ComponentsbugThis issue describes a behavior which is not expected - a bug.This issue describes a behavior which is not expected - a bug.feature-trimming
Milestone
Description
Is there an existing issue for this?
- I have searched the existing issues
Describe the bug
ParserDelegateCache.Get method body suppresses trim analysis warnings with the following justification:
aspnetcore/src/Components/Components/src/BindConverter.cs
Lines 1859 to 1867 in 98ee502
| [UnconditionalSuppressMessage( | |
| "ReflectionAnalysis", | |
| "IL2060:MakeGenericMethod", | |
| Justification = "The referenced methods don't have any DynamicallyAccessedMembers annotations. See https://github.com/mono/linker/issues/1727")] | |
| [UnconditionalSuppressMessage( | |
| "ReflectionAnalysis", | |
| "IL2075:MakeGenericMethod", | |
| Justification = "The referenced methods don't have any DynamicallyAccessedMembers annotations. See https://github.com/mono/linker/issues/1727")] | |
| public static BindParser<T> Get<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] T>() |
This is a lie. At minimum, the following code:
aspnetcore/src/Components/Components/src/BindConverter.cs
Lines 1985 to 1990 in 98ee502
| else if (typeof(T).IsArray) | |
| { | |
| var method = _makeArrayTypeConverter ??= typeof(ParserDelegateCache).GetMethod(nameof(MakeArrayTypeConverter), BindingFlags.NonPublic | BindingFlags.Static)!; | |
| var elementType = typeof(T).GetElementType()!; | |
| parser = (Delegate)method.MakeGenericMethod(elementType).Invoke(null, null)!; | |
| } |
is doing MakeGenericMethod on a method that is annotated. I don't see anything obvious that would ensure this invariant holds:
| private static BindParser<T[]?> MakeArrayTypeConverter<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] T>() |
Trim warning suppressions:
- Should be reviewed with the same level of suspicion as
unsafe. Assume it's a bug unless proven otherwise. - Should never be used on a 130 line method that does tons of reflection. Extract the suppressed block to a small helper method and suppress there.
Expected Behavior
No response
Steps To Reproduce
No response
Exceptions (if any)
No response
.NET Version
No response
Anything else?
No response
Metadata
Metadata
Assignees
Labels
area-blazorIncludes: Blazor, Razor ComponentsIncludes: Blazor, Razor ComponentsbugThis issue describes a behavior which is not expected - a bug.This issue describes a behavior which is not expected - a bug.feature-trimming