Skip to content

fix: AOT compatibility gaps in PropertyInjector and JsonExtensions #4856

@thomhurst

Description

@thomhurst

Description

Several reflection calls lack proper [DynamicallyAccessedMembers] annotations, which can cause runtime failures under AOT trimming.

PropertyInjector.cs (Lines 244, 387, 393, 409)

Direct calls to metadata.ContainingType.GetProperty() without [DynamicallyAccessedMembers] annotations in InjectSourceGeneratedPropertyAsync and RecurseIntoNestedPropertiesCoreAsync. While methods have [UnconditionalSuppressMessage] for source-gen, the actual calls lack proper safeguards.

JsonExtensions.cs (Lines 68, 80)

classParameterTypes[i].FullName ?? "Unknown"

Accesses FullName without checking for null Types. Generic type parameters or constructed types might return null FullName. No DynamicallyAccessedMembers annotation on input types.

Suggested Fix

  • Annotate metadata.ContainingType with [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)]
  • Add null coalescing: classParameterTypes[i]?.FullName ?? classParameterTypes[i]?.Name ?? "Unknown"

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions