Skip to content

Trim analysis warning IL2070 caused by SerializationOptions #294

@runenur

Description

@runenur

Describe the bug

When enabling AOT, a trim analysis warning is logged even though I use the correct JsonSerializerContext overload.

Regression Issue

  • Select this option if this issue appears to be a regression.

Expected Behavior

I expect no trim analysis warnings.

Current Behavior

I get the following warning:

Trim analysis warning IL2070: System.Text.Json.Serialization.Converters.EnumConverterFactory.Create(Type,EnumConverterOptions,JsonNamingPolicy,JsonSerializerOptions): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicParameterlessConstructor' in call to 'System.Type.MakeGenericType(Type[])'. The parameter 'enumType' of method 'System.Text.Json.Serialization.Converters.EnumConverterFactory.
Create(Type,EnumConverterOptions,JsonNamingPolicy,JsonSerializerOptions)' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to.

Reproduction Steps

All you need is a call to AddAWSMessageBus with a JsonSerializerContext and an empty callback. I set the project property TrimmerSingleWarn to false in order to get the exact warning, and not a single generic one.

Possible Solution

After some digging, I found that SerializationOptions creates an instance of JsonStringEnumConverter, which causes the warning. I tried with a custom build of AWS.Messaging that did not create this instance, and the warning went away.

When you provide a JsonSerializerContext, this instance will never be used. But the warning does not seem to be depressed anywhere.

Additional Information/Context

No response

AWS.Messaging (or related) package versions

AWS.Messaging.Lambda 1.0.1

Targeted .NET Platform

.NET 8

Operating System and version

Windows 11

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingp1This is a high priority issuequeued

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions