Skip to content

Invalid trimming suppression in AIJsonUtilities #5629

@eerhardt

Description

@eerhardt

We have the following trimming suppression:

#if !NET9_0_OR_GREATER
[UnconditionalSuppressMessage("Trimming", "IL2026:Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access",
Justification = "Pre STJ-9 schema extraction can fail with a runtime exception if certain reflection metadata have been trimmed. " +
"The exception message will guide users to turn off 'IlcTrimMetadata' which resolves all issues.")]
#endif
private static JsonElement GetJsonSchemaCore(JsonSerializerOptions options, FunctionParameterKey key)

This is an incorrect way to address trimming warnings. The intention of the warnings is so developers now upfront what does and what doesn't work when the build and publish a trimmed or native AOT'd app. Suppressing warnings like this minimizes the principle of "if you don't get warnings during publish, your app is guaranteed to work the same as before you published".

We should remove this suppression and either make the underlying code trim-compatible, or we should annotate this method as RequiresUnreferencedCode.

cc @eiriktsarpalis

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions