Skip to content

Resolve remaining trim analyzer warnings (DynamicallyAccessedMembers pass) #4956

Closed

Description

@rockfordlhotka

Follow-up to #3347 / #4955.

#4340 turned on the trim/AOT analyzers for Csla.csproj and suppressed every resulting warning code in NoWarn. #4955 resolves the RequiresDynamicCode / RequiresUnreferencedCode group (IL2026, IL2055, IL2057, IL2060, IL2096, IL3050) and removes those codes from NoWarn. This issue covers what's left, which is mostly [DynamicallyAccessedMembers] annotation work. That work is trim-friendly and doesn't opt anything out of NativeAOT.

Remaining warnings

Counted by building Source/Csla/Csla.csproj -f net10.0 with the IL codes no longer suppressed, on the #4955 branch:

Code Count Meaning
IL2072 42 Value passed to a [DynamicallyAccessedMembers] parameter/field doesn't carry matching annotations (often obj.GetType() or an unannotated Type return)
IL2070 21 Reflection on a Type parameter that lacks [DynamicallyAccessedMembers]
IL2075 12 Reflection on a Type return value (for example GetType().GetMethod(...)) without annotations
IL2111 51 Method with [DynamicallyAccessedMembers] parameters accessed via reflection (mostly expression-based RegisterProperty<P>(c => c.Prop) in static initializers)
IL2114 1 [DynamicallyAccessedMembers] on ManagedObjectBase references RegisterProperty<P>(Type, PropertyInfo<P>). This one isn't suppressed today and shows in every build.

Files with the most warnings: Server/Hosts/DataPortalChannel/CriteriaRequest.cs (24), DataPortalErrorInfo.cs (18), Reflection/MethodCaller.cs (17), DataPortalT.cs (10), Security/UsernameCriteria.cs (9), Core/FieldManager/FieldDataManager.cs (6).

Approach

Following the burn-down process from #3347:

  1. Remove one code at a time from the <NoWarn> list in Source/Csla/Csla.csproj (IL2070;IL2072;IL2075, then IL2111).
  2. Fix by annotating Type parameters, fields and return values with the narrowest [DynamicallyAccessedMembers] that works, rather than All.
  3. Use [UnconditionalSuppressMessage] only where the requirement provably holds (for example obj.GetType() on a type whose base class already carries the annotation), and always with a justification.
  4. IL2111 is mostly the RegisterProperty expression overloads in generated/DTO-style classes. Check whether those call sites can use the nameof/string overloads, or whether the overloads' annotations can change, before suppressing.

Done when NoWarn in Csla.csproj has no IL codes left and the Csla build produces no IL warnings.

Tip

dotnet build Source/Csla/Csla.csproj -f net10.0 -p:SolutionDir=<abs path to Source>\ -p:NoWarn=CS1591 builds just the core project, so all IL warnings show. A single-project build without SolutionDir fails with CS7027 because of CslaKey.snk.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions