Skip to content

AOT: CommandBuilderBase.GetType().GetProperties() needs DynamicallyAccessedMembers annotation #266

Closed

Description

@jeremydmiller

Surfaced by IsAotCompatible=true on Weasel.Core (landed in Weasel 9.0 foundation):

warning IL2075: 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicProperties' in call to 'System.Type.GetProperties()'. The return value of method 'System.Object.GetType()' does not have matching annotations.

Location: src/Weasel.Core/CommandBuilderBase.cs:300

This is reflective property enumeration on an arbitrary object instance. Two paths:

  1. Annotate the consuming method's generic type parameter (or the parameter being inspected) with [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)] so the trimmer preserves the necessary metadata.
  2. Replace the reflective enumeration with a source-generator-emitted accessor for known types (longer-term, aligns with the source-generator-first direction of the Critter Stack 2026 wave).

Path 1 is the minimum-blast-radius fix; path 2 is the longer-term answer.

Tracked under pillar JasperFx/jasperfx#213.

Activity

  1. added this to the 9.0 milestone on May 11, 2026
  2. added a commit that references this issue on May 12, 2026
  3. jeremydmiller commented on May 12, 2026

    @jeremydmiller
    MemberAuthor

    Resolved by PR #272 (merged into 9.0).

    Two-part fix per path 1 in the issue:

    1. Adds [DynamicallyAccessedMembers(PublicProperties)] on the parameters argument of AddParameters(object) so the runtime contract ("the type you pass me must have its public properties preserved") is part of the caller-facing surface.

    2. Adds [UnconditionalSuppressMessage("Trimming", "IL2075", ...)] on the method with a Justification documenting that the trimmer's flow analysis doesn't currently propagate the DAM annotation through object.GetType() — the runtime contract holds via the parameter annotation, just not the trimmer's static check at the GetType().GetProperties() call site.

    xmldoc points at the source-generator path (path 2 in the issue) as the longer-term answer.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions