-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Labels
area-System.Text.Jsonin-prThere is an active PR which will close this issue when it is mergedThere is an active PR which will close this issue when it is merged
Milestone
Description
Description:
When publishing a .NET application using System.Text.Json with NativeAOT, setting JsonSerializerIsReflectionEnabledByDefault to true triggers the following warning during compilation:
/_/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/EnumConverterFactory.cs(33):
AOT analysis warning IL3050: System.Text.Json.Serialization.Converters.EnumConverterFactory.CreateConverter(Type,JsonSerializerOptions):
Using member 'System.Text.Json.Serialization.Converters.EnumConverterFactory.Create(Type,EnumConverterOptions,JsonNamingPolicy,JsonSerializerOptions)' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling.
JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation.
Use System.Text.Json source generation for native AOT applications.
Repro:
using System.Text.Json;
class Program
{
static void Main()
{
var something = JsonSerializer.Deserialize<String>("{}"); // Any call to JsonSerializer.Deserialize will do
}
}Enable AOT and JsonSerializerIsReflectionEnabledByDefault
<PublishAot>true</PublishAot>
<JsonSerializerIsReflectionEnabledByDefault>true</JsonSerializerIsReflectionEnabledByDefault>dotnet publish -c Release -p:TrimmerSingleWarn=falsePossible cause:
Lines 28 to 34 in 9ecef8c
| [SuppressMessage("AOT", "IL3050:Calling members annotated with 'RequiresDynamicCodeAttribute' may break functionality when AOT compiling.", | |
| Justification = "The constructor has been annotated with RequiredDynamicCodeAttribute.")] | |
| public override JsonConverter CreateConverter(Type type, JsonSerializerOptions options) | |
| { | |
| Debug.Assert(CanConvert(type)); | |
| return Create(type, EnumConverterOptions.AllowNumbers, namingPolicy: null, options); | |
| } |
UnconditionalSuppressMessage ?
Context:
The issue was found in MAUI - dotnet/maui#25077
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
area-System.Text.Jsonin-prThere is an active PR which will close this issue when it is mergedThere is an active PR which will close this issue when it is merged