From 13380830113e063d8056352a5c326c829f630520 Mon Sep 17 00:00:00 2001 From: Lakshan Fernando Date: Sun, 24 Apr 2022 06:15:05 -0700 Subject: [PATCH 1/9] Annotating System.Text.Json library for aot form factor --- .../RequiresDynamicCodeAttribute.cs | 7 +- .../System.Text.Json/ref/System.Text.Json.cs | 189 +++++++++++------- .../ref/System.Text.Json.csproj | 1 + .../src/System.Text.Json.csproj | 1 + .../src/System/Text/Json/Nodes/JsonArray.cs | 1 + .../src/System/Text/Json/Nodes/JsonValue.cs | 1 + .../Text/Json/Nodes/JsonValueNotTrimmable.cs | 3 + .../IAsyncEnumerableConverterFactory.cs | 5 +- .../Collection/IEnumerableConverterFactory.cs | 3 + .../IEnumerableConverterFactoryHelpers.cs | 4 + ...naryOfTKeyTValueConverterWithReflection.cs | 2 + ...bleEnumerableOfTConverterWithReflection.cs | 2 + .../StackOrQueueConverterWithReflection.cs | 2 + .../Converters/FSharp/FSharpListConverter.cs | 3 +- .../Converters/FSharp/FSharpMapConverter.cs | 3 +- .../FSharp/FSharpOptionConverter.cs | 3 +- .../Converters/FSharp/FSharpSetConverter.cs | 3 +- .../FSharp/FSharpTypeConverterFactory.cs | 7 +- .../FSharp/FSharpValueOptionConverter.cs | 3 +- .../Object/ObjectConverterFactory.cs | 4 + ...edConstructorConverter.Large.Reflection.cs | 2 + .../Converters/Value/EnumConverterFactory.cs | 2 + .../Value/NullableConverterFactory.cs | 2 + .../Value/UnsupportedTypeConverterFactory.cs | 3 + .../Text/Json/Serialization/JsonConverter.cs | 1 + .../Serialization/JsonSerializer.Helpers.cs | 4 +- .../JsonSerializer.Read.Document.cs | 2 + .../JsonSerializer.Read.Element.cs | 2 + .../Serialization/JsonSerializer.Read.Node.cs | 2 + .../Serialization/JsonSerializer.Read.Span.cs | 2 + .../JsonSerializer.Read.Stream.cs | 8 + .../JsonSerializer.Read.String.cs | 4 + .../JsonSerializer.Read.Utf8JsonReader.cs | 2 + .../JsonSerializer.Write.ByteArray.cs | 2 + .../JsonSerializer.Write.Document.cs | 2 + .../JsonSerializer.Write.Element.cs | 2 + .../JsonSerializer.Write.Node.cs | 2 + .../JsonSerializer.Write.Stream.cs | 4 + .../JsonSerializer.Write.String.cs | 2 + .../JsonSerializer.Write.Utf8JsonWriter.cs | 2 + .../JsonSerializerOptions.Converters.cs | 5 + .../Serialization/JsonSerializerOptions.cs | 3 +- .../JsonSerializerOptionsUpdateHandler.cs | 2 + .../Serialization/JsonStringEnumConverter.cs | 3 + .../Metadata/FSharpCoreReflectionProxy.cs | 12 +- .../Serialization/Metadata/MemberAccessor.cs | 1 + .../ReflectionEmitCachingMemberAccessor.cs | 3 +- .../Metadata/ReflectionEmitMemberAccessor.cs | 3 + .../Metadata/ReflectionJsonTypeInfoOfT.cs | 7 +- .../Metadata/ReflectionMemberAccessor.cs | 1 + 50 files changed, 251 insertions(+), 88 deletions(-) diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/CodeAnalysis/RequiresDynamicCodeAttribute.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/CodeAnalysis/RequiresDynamicCodeAttribute.cs index 157b06404580dd..e2df463a043eb0 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/CodeAnalysis/RequiresDynamicCodeAttribute.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/CodeAnalysis/RequiresDynamicCodeAttribute.cs @@ -11,7 +11,12 @@ namespace System.Diagnostics.CodeAnalysis /// This allows tools to understand which methods are unsafe to call when compiling ahead of time. /// [AttributeUsage(AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Class, Inherited = false)] - public sealed class RequiresDynamicCodeAttribute : Attribute +#if SYSTEM_PRIVATE_CORELIB + public +#else + internal +#endif + sealed class RequiresDynamicCodeAttribute : Attribute { /// /// Initializes a new instance of the class diff --git a/src/libraries/System.Text.Json/ref/System.Text.Json.cs b/src/libraries/System.Text.Json/ref/System.Text.Json.cs index 6dd9befb4893ce..47e48759ab169f 100644 --- a/src/libraries/System.Text.Json/ref/System.Text.Json.cs +++ b/src/libraries/System.Text.Json/ref/System.Text.Json.cs @@ -187,107 +187,142 @@ public partial struct JsonReaderState public static partial class JsonSerializer { [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")] + [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use source generated paths for native aot applications.")] public static object? Deserialize(System.IO.Stream utf8Json, System.Type returnType, System.Text.Json.JsonSerializerOptions? options = null) { throw null; } public static object? Deserialize(System.IO.Stream utf8Json, System.Type returnType, System.Text.Json.Serialization.JsonSerializerContext context) { throw null; } [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")] + [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use source generated paths for native aot applications.")] public static object? Deserialize(System.ReadOnlySpan utf8Json, System.Type returnType, System.Text.Json.JsonSerializerOptions? options = null) { throw null; } public static object? Deserialize(System.ReadOnlySpan utf8Json, System.Type returnType, System.Text.Json.Serialization.JsonSerializerContext context) { throw null; } [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")] + [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use source generated paths for native aot applications.")] public static object? Deserialize([System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("Json")] System.ReadOnlySpan json, System.Type returnType, System.Text.Json.JsonSerializerOptions? options = null) { throw null; } public static object? Deserialize([System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("Json")] System.ReadOnlySpan json, System.Type returnType, System.Text.Json.Serialization.JsonSerializerContext context) { throw null; } [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")] + [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use source generated paths for native aot applications.")] public static object? Deserialize([System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("Json")] string json, System.Type returnType, System.Text.Json.JsonSerializerOptions? options = null) { throw null; } public static object? Deserialize([System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("Json")] string json, System.Type returnType, System.Text.Json.Serialization.JsonSerializerContext context) { throw null; } [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")] + [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use source generated paths for native aot applications.")] public static object? Deserialize(this System.Text.Json.JsonDocument document, System.Type returnType, System.Text.Json.JsonSerializerOptions? options = null) { throw null; } public static object? Deserialize(this System.Text.Json.JsonDocument document, System.Type returnType, System.Text.Json.Serialization.JsonSerializerContext context) { throw null; } [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")] + [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use source generated paths for native aot applications.")] public static object? Deserialize(this System.Text.Json.JsonElement element, System.Type returnType, System.Text.Json.JsonSerializerOptions? options = null) { throw null; } public static object? Deserialize(this System.Text.Json.JsonElement element, System.Type returnType, System.Text.Json.Serialization.JsonSerializerContext context) { throw null; } [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")] + [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use source generated paths for native aot applications.")] public static object? Deserialize(this System.Text.Json.Nodes.JsonNode? node, System.Type returnType, System.Text.Json.JsonSerializerOptions? options = null) { throw null; } public static object? Deserialize(this System.Text.Json.Nodes.JsonNode? node, System.Type returnType, System.Text.Json.Serialization.JsonSerializerContext context) { throw null; } [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")] + [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use source generated paths for native aot applications.")] public static object? Deserialize(ref System.Text.Json.Utf8JsonReader reader, System.Type returnType, System.Text.Json.JsonSerializerOptions? options = null) { throw null; } public static object? Deserialize(ref System.Text.Json.Utf8JsonReader reader, System.Type returnType, System.Text.Json.Serialization.JsonSerializerContext context) { throw null; } [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")] + [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use source generated paths for native aot applications.")] public static System.Threading.Tasks.ValueTask DeserializeAsync(System.IO.Stream utf8Json, System.Type returnType, System.Text.Json.JsonSerializerOptions? options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public static System.Threading.Tasks.ValueTask DeserializeAsync(System.IO.Stream utf8Json, System.Type returnType, System.Text.Json.Serialization.JsonSerializerContext context, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")] + [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use source generated paths for native aot applications.")] public static System.Collections.Generic.IAsyncEnumerable DeserializeAsyncEnumerable(System.IO.Stream utf8Json, System.Text.Json.JsonSerializerOptions? options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")] + [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use source generated paths for native aot applications.")] public static System.Threading.Tasks.ValueTask DeserializeAsync(System.IO.Stream utf8Json, System.Text.Json.JsonSerializerOptions? options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public static System.Threading.Tasks.ValueTask DeserializeAsync(System.IO.Stream utf8Json, System.Text.Json.Serialization.Metadata.JsonTypeInfo jsonTypeInfo, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")] + [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use source generated paths for native aot applications.")] public static TValue? Deserialize(System.IO.Stream utf8Json, System.Text.Json.JsonSerializerOptions? options = null) { throw null; } public static TValue? Deserialize(System.IO.Stream utf8Json, System.Text.Json.Serialization.Metadata.JsonTypeInfo jsonTypeInfo) { throw null; } [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")] + [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use source generated paths for native aot applications.")] public static TValue? Deserialize(System.ReadOnlySpan utf8Json, System.Text.Json.JsonSerializerOptions? options = null) { throw null; } public static TValue? Deserialize(System.ReadOnlySpan utf8Json, System.Text.Json.Serialization.Metadata.JsonTypeInfo jsonTypeInfo) { throw null; } [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")] + [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use source generated paths for native aot applications.")] public static TValue? Deserialize([System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("Json")] System.ReadOnlySpan json, System.Text.Json.JsonSerializerOptions? options = null) { throw null; } public static TValue? Deserialize([System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("Json")] System.ReadOnlySpan json, System.Text.Json.Serialization.Metadata.JsonTypeInfo jsonTypeInfo) { throw null; } [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")] + [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use source generated paths for native aot applications.")] public static TValue? Deserialize([System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("Json")] string json, System.Text.Json.JsonSerializerOptions? options = null) { throw null; } public static TValue? Deserialize([System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("Json")] string json, System.Text.Json.Serialization.Metadata.JsonTypeInfo jsonTypeInfo) { throw null; } [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")] + [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use source generated paths for native aot applications.")] public static TValue? Deserialize(this System.Text.Json.JsonDocument document, System.Text.Json.JsonSerializerOptions? options = null) { throw null; } public static TValue? Deserialize(this System.Text.Json.JsonDocument document, System.Text.Json.Serialization.Metadata.JsonTypeInfo jsonTypeInfo) { throw null; } [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")] + [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use source generated paths for native aot applications.")] public static TValue? Deserialize(this System.Text.Json.JsonElement element, System.Text.Json.JsonSerializerOptions? options = null) { throw null; } public static TValue? Deserialize(this System.Text.Json.JsonElement element, System.Text.Json.Serialization.Metadata.JsonTypeInfo jsonTypeInfo) { throw null; } [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")] + [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use source generated paths for native aot applications.")] public static TValue? Deserialize(this System.Text.Json.Nodes.JsonNode? node, System.Text.Json.JsonSerializerOptions? options = null) { throw null; } public static TValue? Deserialize(this System.Text.Json.Nodes.JsonNode? node, System.Text.Json.Serialization.Metadata.JsonTypeInfo jsonTypeInfo) { throw null; } [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")] - public static TValue? Deserialize< TValue>(ref System.Text.Json.Utf8JsonReader reader, System.Text.Json.JsonSerializerOptions? options = null) { throw null; } + [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use source generated paths for native aot applications.")] + public static TValue? Deserialize(ref System.Text.Json.Utf8JsonReader reader, System.Text.Json.JsonSerializerOptions? options = null) { throw null; } public static TValue? Deserialize(ref System.Text.Json.Utf8JsonReader reader, System.Text.Json.Serialization.Metadata.JsonTypeInfo jsonTypeInfo) { throw null; } [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")] + [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use source generated paths for native aot applications.")] public static void Serialize(System.IO.Stream utf8Json, object? value, System.Type inputType, System.Text.Json.JsonSerializerOptions? options = null) { } public static void Serialize(System.IO.Stream utf8Json, object? value, System.Type inputType, System.Text.Json.Serialization.JsonSerializerContext context) { } [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")] + [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use source generated paths for native aot applications.")] public static string Serialize(object? value, System.Type inputType, System.Text.Json.JsonSerializerOptions? options = null) { throw null; } public static string Serialize(object? value, System.Type inputType, System.Text.Json.Serialization.JsonSerializerContext context) { throw null; } [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")] + [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use source generated paths for native aot applications.")] public static void Serialize(System.Text.Json.Utf8JsonWriter writer, object? value, System.Type inputType, System.Text.Json.JsonSerializerOptions? options = null) { } public static void Serialize(System.Text.Json.Utf8JsonWriter writer, object? value, System.Type inputType, System.Text.Json.Serialization.JsonSerializerContext context) { } [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")] + [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use source generated paths for native aot applications.")] public static System.Threading.Tasks.Task SerializeAsync(System.IO.Stream utf8Json, object? value, System.Type inputType, System.Text.Json.JsonSerializerOptions? options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public static System.Threading.Tasks.Task SerializeAsync(System.IO.Stream utf8Json, object? value, System.Type inputType, System.Text.Json.Serialization.JsonSerializerContext context, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")] + [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use source generated paths for native aot applications.")] public static System.Threading.Tasks.Task SerializeAsync(System.IO.Stream utf8Json, TValue value, System.Text.Json.JsonSerializerOptions? options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public static System.Threading.Tasks.Task SerializeAsync(System.IO.Stream utf8Json, TValue value, System.Text.Json.Serialization.Metadata.JsonTypeInfo jsonTypeInfo, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")] + [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use source generated paths for native aot applications.")] public static System.Text.Json.JsonDocument SerializeToDocument(object? value, System.Type inputType, System.Text.Json.JsonSerializerOptions? options = null) { throw null; } public static System.Text.Json.JsonDocument SerializeToDocument(object? value, System.Type inputType, System.Text.Json.Serialization.JsonSerializerContext context) { throw null; } [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")] + [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use source generated paths for native aot applications.")] public static System.Text.Json.JsonDocument SerializeToDocument(TValue value, System.Text.Json.JsonSerializerOptions? options = null) { throw null; } public static System.Text.Json.JsonDocument SerializeToDocument(TValue value, System.Text.Json.Serialization.Metadata.JsonTypeInfo jsonTypeInfo) { throw null; } [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")] + [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use source generated paths for native aot applications.")] public static System.Text.Json.JsonElement SerializeToElement(object? value, System.Type inputType, System.Text.Json.JsonSerializerOptions? options = null) { throw null; } public static System.Text.Json.JsonElement SerializeToElement(object? value, System.Type inputType, System.Text.Json.Serialization.JsonSerializerContext context) { throw null; } [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")] + [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use source generated paths for native aot applications.")] public static System.Text.Json.JsonElement SerializeToElement(TValue value, System.Text.Json.JsonSerializerOptions? options = null) { throw null; } public static System.Text.Json.JsonElement SerializeToElement(TValue value, System.Text.Json.Serialization.Metadata.JsonTypeInfo jsonTypeInfo) { throw null; } [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")] + [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use source generated paths for native aot applications.")] public static System.Text.Json.Nodes.JsonNode? SerializeToNode(object? value, System.Type inputType, System.Text.Json.JsonSerializerOptions? options = null) { throw null; } public static System.Text.Json.Nodes.JsonNode? SerializeToNode(object? value, System.Type inputType, System.Text.Json.Serialization.JsonSerializerContext context) { throw null; } [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")] + [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use source generated paths for native aot applications.")] public static System.Text.Json.Nodes.JsonNode? SerializeToNode(TValue value, System.Text.Json.JsonSerializerOptions? options = null) { throw null; } public static System.Text.Json.Nodes.JsonNode? SerializeToNode(TValue value, System.Text.Json.Serialization.Metadata.JsonTypeInfo jsonTypeInfo) { throw null; } [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")] + [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use source generated paths for native aot applications.")] public static byte[] SerializeToUtf8Bytes(object? value, System.Type inputType, System.Text.Json.JsonSerializerOptions? options = null) { throw null; } public static byte[] SerializeToUtf8Bytes(object? value, System.Type inputType, System.Text.Json.Serialization.JsonSerializerContext context) { throw null; } [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")] + [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use source generated paths for native aot applications.")] public static byte[] SerializeToUtf8Bytes(TValue value, System.Text.Json.JsonSerializerOptions? options = null) { throw null; } public static byte[] SerializeToUtf8Bytes(TValue value, System.Text.Json.Serialization.Metadata.JsonTypeInfo jsonTypeInfo) { throw null; } [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")] + [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use source generated paths for native aot applications.")] public static void Serialize(System.IO.Stream utf8Json, TValue value, System.Text.Json.JsonSerializerOptions? options = null) { } public static void Serialize(System.IO.Stream utf8Json, TValue value, System.Text.Json.Serialization.Metadata.JsonTypeInfo jsonTypeInfo) { } [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")] + [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use source generated paths for native aot applications.")] public static void Serialize(System.Text.Json.Utf8JsonWriter writer, TValue value, System.Text.Json.JsonSerializerOptions? options = null) { } public static void Serialize(System.Text.Json.Utf8JsonWriter writer, TValue value, System.Text.Json.Serialization.Metadata.JsonTypeInfo jsonTypeInfo) { } [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")] + [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use source generated paths for native aot applications.")] public static string Serialize(TValue value, System.Text.Json.JsonSerializerOptions? options = null) { throw null; } public static string Serialize(TValue value, System.Text.Json.Serialization.Metadata.JsonTypeInfo jsonTypeInfo) { throw null; } } @@ -325,6 +360,7 @@ public JsonSerializerOptions(System.Text.Json.JsonSerializerOptions options) { } public bool WriteIndented { get { throw null; } set { } } public void AddContext() where TContext : System.Text.Json.Serialization.JsonSerializerContext, new() { } [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Getting a converter for a type may require reflection which depends on unreferenced code.")] + [System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Getting a converter for a type may require reflection which depends on unreferenced code.")] public System.Text.Json.Serialization.JsonConverter GetConverter(System.Type typeToConvert) { throw null; } } public enum JsonTokenType : byte @@ -573,6 +609,7 @@ public JsonArray(params System.Text.Json.Nodes.JsonNode?[] items) { } bool System.Collections.Generic.ICollection.IsReadOnly { get { throw null; } } public void Add(System.Text.Json.Nodes.JsonNode? item) { } [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Creating JsonValue instances with non-primitive types is not compatible with trimming. It can result in non-primitive types being serialized, which may have their members trimmed.")] + [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("Creating JsonValue instances with non-primitive types is not compatible with trimming. It can result in non-primitive types being serialized, which may have their members trimmed.")] public void Add(T? value) { } public void Clear() { } public bool Contains(System.Text.Json.Nodes.JsonNode? item) { throw null; } @@ -599,88 +636,88 @@ internal JsonNode() { } public System.Text.Json.Nodes.JsonValue AsValue() { throw null; } public string GetPath() { throw null; } public virtual T GetValue() { throw null; } - public static explicit operator bool (System.Text.Json.Nodes.JsonNode value) { throw null; } - public static explicit operator byte (System.Text.Json.Nodes.JsonNode value) { throw null; } - public static explicit operator char (System.Text.Json.Nodes.JsonNode value) { throw null; } - public static explicit operator System.DateTime (System.Text.Json.Nodes.JsonNode value) { throw null; } - public static explicit operator System.DateTimeOffset (System.Text.Json.Nodes.JsonNode value) { throw null; } - public static explicit operator decimal (System.Text.Json.Nodes.JsonNode value) { throw null; } - public static explicit operator double (System.Text.Json.Nodes.JsonNode value) { throw null; } - public static explicit operator System.Guid (System.Text.Json.Nodes.JsonNode value) { throw null; } - public static explicit operator short (System.Text.Json.Nodes.JsonNode value) { throw null; } - public static explicit operator int (System.Text.Json.Nodes.JsonNode value) { throw null; } - public static explicit operator long (System.Text.Json.Nodes.JsonNode value) { throw null; } - public static explicit operator bool? (System.Text.Json.Nodes.JsonNode? value) { throw null; } - public static explicit operator byte? (System.Text.Json.Nodes.JsonNode? value) { throw null; } - public static explicit operator char? (System.Text.Json.Nodes.JsonNode? value) { throw null; } - public static explicit operator System.DateTimeOffset? (System.Text.Json.Nodes.JsonNode? value) { throw null; } - public static explicit operator System.DateTime? (System.Text.Json.Nodes.JsonNode? value) { throw null; } - public static explicit operator decimal? (System.Text.Json.Nodes.JsonNode? value) { throw null; } - public static explicit operator double? (System.Text.Json.Nodes.JsonNode? value) { throw null; } - public static explicit operator System.Guid? (System.Text.Json.Nodes.JsonNode? value) { throw null; } - public static explicit operator short? (System.Text.Json.Nodes.JsonNode? value) { throw null; } - public static explicit operator int? (System.Text.Json.Nodes.JsonNode? value) { throw null; } - public static explicit operator long? (System.Text.Json.Nodes.JsonNode? value) { throw null; } + public static explicit operator bool(System.Text.Json.Nodes.JsonNode value) { throw null; } + public static explicit operator byte(System.Text.Json.Nodes.JsonNode value) { throw null; } + public static explicit operator char(System.Text.Json.Nodes.JsonNode value) { throw null; } + public static explicit operator System.DateTime(System.Text.Json.Nodes.JsonNode value) { throw null; } + public static explicit operator System.DateTimeOffset(System.Text.Json.Nodes.JsonNode value) { throw null; } + public static explicit operator decimal(System.Text.Json.Nodes.JsonNode value) { throw null; } + public static explicit operator double(System.Text.Json.Nodes.JsonNode value) { throw null; } + public static explicit operator System.Guid(System.Text.Json.Nodes.JsonNode value) { throw null; } + public static explicit operator short(System.Text.Json.Nodes.JsonNode value) { throw null; } + public static explicit operator int(System.Text.Json.Nodes.JsonNode value) { throw null; } + public static explicit operator long(System.Text.Json.Nodes.JsonNode value) { throw null; } + public static explicit operator bool?(System.Text.Json.Nodes.JsonNode? value) { throw null; } + public static explicit operator byte?(System.Text.Json.Nodes.JsonNode? value) { throw null; } + public static explicit operator char?(System.Text.Json.Nodes.JsonNode? value) { throw null; } + public static explicit operator System.DateTimeOffset?(System.Text.Json.Nodes.JsonNode? value) { throw null; } + public static explicit operator System.DateTime?(System.Text.Json.Nodes.JsonNode? value) { throw null; } + public static explicit operator decimal?(System.Text.Json.Nodes.JsonNode? value) { throw null; } + public static explicit operator double?(System.Text.Json.Nodes.JsonNode? value) { throw null; } + public static explicit operator System.Guid?(System.Text.Json.Nodes.JsonNode? value) { throw null; } + public static explicit operator short?(System.Text.Json.Nodes.JsonNode? value) { throw null; } + public static explicit operator int?(System.Text.Json.Nodes.JsonNode? value) { throw null; } + public static explicit operator long?(System.Text.Json.Nodes.JsonNode? value) { throw null; } [System.CLSCompliantAttribute(false)] - public static explicit operator sbyte? (System.Text.Json.Nodes.JsonNode? value) { throw null; } - public static explicit operator float? (System.Text.Json.Nodes.JsonNode? value) { throw null; } + public static explicit operator sbyte?(System.Text.Json.Nodes.JsonNode? value) { throw null; } + public static explicit operator float?(System.Text.Json.Nodes.JsonNode? value) { throw null; } [System.CLSCompliantAttribute(false)] - public static explicit operator ushort? (System.Text.Json.Nodes.JsonNode? value) { throw null; } + public static explicit operator ushort?(System.Text.Json.Nodes.JsonNode? value) { throw null; } [System.CLSCompliantAttribute(false)] - public static explicit operator uint? (System.Text.Json.Nodes.JsonNode? value) { throw null; } + public static explicit operator uint?(System.Text.Json.Nodes.JsonNode? value) { throw null; } [System.CLSCompliantAttribute(false)] - public static explicit operator ulong? (System.Text.Json.Nodes.JsonNode? value) { throw null; } + public static explicit operator ulong?(System.Text.Json.Nodes.JsonNode? value) { throw null; } [System.CLSCompliantAttribute(false)] - public static explicit operator sbyte (System.Text.Json.Nodes.JsonNode value) { throw null; } - public static explicit operator float (System.Text.Json.Nodes.JsonNode value) { throw null; } - public static explicit operator string? (System.Text.Json.Nodes.JsonNode? value) { throw null; } + public static explicit operator sbyte(System.Text.Json.Nodes.JsonNode value) { throw null; } + public static explicit operator float(System.Text.Json.Nodes.JsonNode value) { throw null; } + public static explicit operator string?(System.Text.Json.Nodes.JsonNode? value) { throw null; } [System.CLSCompliantAttribute(false)] - public static explicit operator ushort (System.Text.Json.Nodes.JsonNode value) { throw null; } + public static explicit operator ushort(System.Text.Json.Nodes.JsonNode value) { throw null; } [System.CLSCompliantAttribute(false)] - public static explicit operator uint (System.Text.Json.Nodes.JsonNode value) { throw null; } + public static explicit operator uint(System.Text.Json.Nodes.JsonNode value) { throw null; } [System.CLSCompliantAttribute(false)] - public static explicit operator ulong (System.Text.Json.Nodes.JsonNode value) { throw null; } - public static implicit operator System.Text.Json.Nodes.JsonNode (bool value) { throw null; } - public static implicit operator System.Text.Json.Nodes.JsonNode (byte value) { throw null; } - public static implicit operator System.Text.Json.Nodes.JsonNode (char value) { throw null; } - public static implicit operator System.Text.Json.Nodes.JsonNode (System.DateTime value) { throw null; } - public static implicit operator System.Text.Json.Nodes.JsonNode (System.DateTimeOffset value) { throw null; } - public static implicit operator System.Text.Json.Nodes.JsonNode (decimal value) { throw null; } - public static implicit operator System.Text.Json.Nodes.JsonNode (double value) { throw null; } - public static implicit operator System.Text.Json.Nodes.JsonNode (System.Guid value) { throw null; } - public static implicit operator System.Text.Json.Nodes.JsonNode (short value) { throw null; } - public static implicit operator System.Text.Json.Nodes.JsonNode (int value) { throw null; } - public static implicit operator System.Text.Json.Nodes.JsonNode (long value) { throw null; } - public static implicit operator System.Text.Json.Nodes.JsonNode? (bool? value) { throw null; } - public static implicit operator System.Text.Json.Nodes.JsonNode? (byte? value) { throw null; } - public static implicit operator System.Text.Json.Nodes.JsonNode? (char? value) { throw null; } - public static implicit operator System.Text.Json.Nodes.JsonNode? (System.DateTimeOffset? value) { throw null; } - public static implicit operator System.Text.Json.Nodes.JsonNode? (System.DateTime? value) { throw null; } - public static implicit operator System.Text.Json.Nodes.JsonNode? (decimal? value) { throw null; } - public static implicit operator System.Text.Json.Nodes.JsonNode? (double? value) { throw null; } - public static implicit operator System.Text.Json.Nodes.JsonNode? (System.Guid? value) { throw null; } - public static implicit operator System.Text.Json.Nodes.JsonNode? (short? value) { throw null; } - public static implicit operator System.Text.Json.Nodes.JsonNode? (int? value) { throw null; } - public static implicit operator System.Text.Json.Nodes.JsonNode? (long? value) { throw null; } + public static explicit operator ulong(System.Text.Json.Nodes.JsonNode value) { throw null; } + public static implicit operator System.Text.Json.Nodes.JsonNode(bool value) { throw null; } + public static implicit operator System.Text.Json.Nodes.JsonNode(byte value) { throw null; } + public static implicit operator System.Text.Json.Nodes.JsonNode(char value) { throw null; } + public static implicit operator System.Text.Json.Nodes.JsonNode(System.DateTime value) { throw null; } + public static implicit operator System.Text.Json.Nodes.JsonNode(System.DateTimeOffset value) { throw null; } + public static implicit operator System.Text.Json.Nodes.JsonNode(decimal value) { throw null; } + public static implicit operator System.Text.Json.Nodes.JsonNode(double value) { throw null; } + public static implicit operator System.Text.Json.Nodes.JsonNode(System.Guid value) { throw null; } + public static implicit operator System.Text.Json.Nodes.JsonNode(short value) { throw null; } + public static implicit operator System.Text.Json.Nodes.JsonNode(int value) { throw null; } + public static implicit operator System.Text.Json.Nodes.JsonNode(long value) { throw null; } + public static implicit operator System.Text.Json.Nodes.JsonNode?(bool? value) { throw null; } + public static implicit operator System.Text.Json.Nodes.JsonNode?(byte? value) { throw null; } + public static implicit operator System.Text.Json.Nodes.JsonNode?(char? value) { throw null; } + public static implicit operator System.Text.Json.Nodes.JsonNode?(System.DateTimeOffset? value) { throw null; } + public static implicit operator System.Text.Json.Nodes.JsonNode?(System.DateTime? value) { throw null; } + public static implicit operator System.Text.Json.Nodes.JsonNode?(decimal? value) { throw null; } + public static implicit operator System.Text.Json.Nodes.JsonNode?(double? value) { throw null; } + public static implicit operator System.Text.Json.Nodes.JsonNode?(System.Guid? value) { throw null; } + public static implicit operator System.Text.Json.Nodes.JsonNode?(short? value) { throw null; } + public static implicit operator System.Text.Json.Nodes.JsonNode?(int? value) { throw null; } + public static implicit operator System.Text.Json.Nodes.JsonNode?(long? value) { throw null; } [System.CLSCompliantAttribute(false)] - public static implicit operator System.Text.Json.Nodes.JsonNode? (sbyte? value) { throw null; } - public static implicit operator System.Text.Json.Nodes.JsonNode? (float? value) { throw null; } + public static implicit operator System.Text.Json.Nodes.JsonNode?(sbyte? value) { throw null; } + public static implicit operator System.Text.Json.Nodes.JsonNode?(float? value) { throw null; } [System.CLSCompliantAttribute(false)] - public static implicit operator System.Text.Json.Nodes.JsonNode? (ushort? value) { throw null; } + public static implicit operator System.Text.Json.Nodes.JsonNode?(ushort? value) { throw null; } [System.CLSCompliantAttribute(false)] - public static implicit operator System.Text.Json.Nodes.JsonNode? (uint? value) { throw null; } + public static implicit operator System.Text.Json.Nodes.JsonNode?(uint? value) { throw null; } [System.CLSCompliantAttribute(false)] - public static implicit operator System.Text.Json.Nodes.JsonNode? (ulong? value) { throw null; } + public static implicit operator System.Text.Json.Nodes.JsonNode?(ulong? value) { throw null; } [System.CLSCompliantAttribute(false)] - public static implicit operator System.Text.Json.Nodes.JsonNode (sbyte value) { throw null; } - public static implicit operator System.Text.Json.Nodes.JsonNode (float value) { throw null; } - public static implicit operator System.Text.Json.Nodes.JsonNode? (string? value) { throw null; } + public static implicit operator System.Text.Json.Nodes.JsonNode(sbyte value) { throw null; } + public static implicit operator System.Text.Json.Nodes.JsonNode(float value) { throw null; } + public static implicit operator System.Text.Json.Nodes.JsonNode?(string? value) { throw null; } [System.CLSCompliantAttribute(false)] - public static implicit operator System.Text.Json.Nodes.JsonNode (ushort value) { throw null; } + public static implicit operator System.Text.Json.Nodes.JsonNode(ushort value) { throw null; } [System.CLSCompliantAttribute(false)] - public static implicit operator System.Text.Json.Nodes.JsonNode (uint value) { throw null; } + public static implicit operator System.Text.Json.Nodes.JsonNode(uint value) { throw null; } [System.CLSCompliantAttribute(false)] - public static implicit operator System.Text.Json.Nodes.JsonNode (ulong value) { throw null; } + public static implicit operator System.Text.Json.Nodes.JsonNode(ulong value) { throw null; } public static System.Text.Json.Nodes.JsonNode? Parse(System.IO.Stream utf8Json, System.Text.Json.Nodes.JsonNodeOptions? nodeOptions = default(System.Text.Json.Nodes.JsonNodeOptions?), System.Text.Json.JsonDocumentOptions documentOptions = default(System.Text.Json.JsonDocumentOptions)) { throw null; } public static System.Text.Json.Nodes.JsonNode? Parse(System.ReadOnlySpan utf8Json, System.Text.Json.Nodes.JsonNodeOptions? nodeOptions = default(System.Text.Json.Nodes.JsonNodeOptions?), System.Text.Json.JsonDocumentOptions documentOptions = default(System.Text.Json.JsonDocumentOptions)) { throw null; } public static System.Text.Json.Nodes.JsonNode? Parse([System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("Json")] string json, System.Text.Json.Nodes.JsonNodeOptions? nodeOptions = default(System.Text.Json.Nodes.JsonNodeOptions?), System.Text.Json.JsonDocumentOptions documentOptions = default(System.Text.Json.JsonDocumentOptions)) { throw null; } @@ -765,6 +802,7 @@ public abstract partial class JsonValue : System.Text.Json.Nodes.JsonNode public static System.Text.Json.Nodes.JsonValue Create(ulong value, System.Text.Json.Nodes.JsonNodeOptions? options = default(System.Text.Json.Nodes.JsonNodeOptions?)) { throw null; } public static System.Text.Json.Nodes.JsonValue? Create(T? value, System.Text.Json.Serialization.Metadata.JsonTypeInfo jsonTypeInfo, System.Text.Json.Nodes.JsonNodeOptions? options = default(System.Text.Json.Nodes.JsonNodeOptions?)) { throw null; } [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Creating JsonValue instances with non-primitive types is not compatible with trimming. It can result in non-primitive types being serialized, which may have their members trimmed. Use the overload that takes a JsonTypeInfo, or make sure all of the required types are preserved.")] + [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("Creating JsonValue instances with non-primitive types is not compatible with trimming. It can result in non-primitive types being serialized, which may have their members trimmed. Use the overload that takes a JsonTypeInfo, or make sure all of the required types are preserved.")] public static System.Text.Json.Nodes.JsonValue? Create(T? value, System.Text.Json.Nodes.JsonNodeOptions? options = default(System.Text.Json.Nodes.JsonNodeOptions?)) { throw null; } public abstract bool TryGetValue([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] out T? value); } @@ -791,7 +829,7 @@ public abstract partial class JsonAttribute : System.Attribute { protected JsonAttribute() { } } - [System.AttributeUsageAttribute(System.AttributeTargets.Constructor, AllowMultiple=false)] + [System.AttributeUsageAttribute(System.AttributeTargets.Constructor, AllowMultiple = false)] public sealed partial class JsonConstructorAttribute : System.Text.Json.Serialization.JsonAttribute { public JsonConstructorAttribute() { } @@ -838,12 +876,12 @@ public JsonDerivedTypeAttribute(System.Type derivedType, string typeDiscriminato public System.Type DerivedType { get { throw null; } } public string? TypeDiscriminatorId { get { throw null; } } } - [System.AttributeUsageAttribute(System.AttributeTargets.Field | System.AttributeTargets.Property, AllowMultiple=false)] + [System.AttributeUsageAttribute(System.AttributeTargets.Field | System.AttributeTargets.Property, AllowMultiple = false)] public sealed partial class JsonExtensionDataAttribute : System.Text.Json.Serialization.JsonAttribute { public JsonExtensionDataAttribute() { } } - [System.AttributeUsageAttribute(System.AttributeTargets.Field | System.AttributeTargets.Property, AllowMultiple=false)] + [System.AttributeUsageAttribute(System.AttributeTargets.Field | System.AttributeTargets.Property, AllowMultiple = false)] public sealed partial class JsonIgnoreAttribute : System.Text.Json.Serialization.JsonAttribute { public JsonIgnoreAttribute() { } @@ -856,7 +894,7 @@ public enum JsonIgnoreCondition WhenWritingDefault = 2, WhenWritingNull = 3, } - [System.AttributeUsageAttribute(System.AttributeTargets.Field | System.AttributeTargets.Property, AllowMultiple=false)] + [System.AttributeUsageAttribute(System.AttributeTargets.Field | System.AttributeTargets.Property, AllowMultiple = false)] public sealed partial class JsonIncludeAttribute : System.Text.Json.Serialization.JsonAttribute { public JsonIncludeAttribute() { } @@ -874,7 +912,7 @@ public enum JsonNumberHandling WriteAsString = 2, AllowNamedFloatingPointLiterals = 4, } - [System.AttributeUsageAttribute(System.AttributeTargets.Class | System.AttributeTargets.Field | System.AttributeTargets.Property | System.AttributeTargets.Struct, AllowMultiple=false)] + [System.AttributeUsageAttribute(System.AttributeTargets.Class | System.AttributeTargets.Field | System.AttributeTargets.Property | System.AttributeTargets.Struct, AllowMultiple = false)] public sealed partial class JsonNumberHandlingAttribute : System.Text.Json.Serialization.JsonAttribute { public JsonNumberHandlingAttribute(System.Text.Json.Serialization.JsonNumberHandling handling) { } @@ -888,7 +926,7 @@ public JsonPolymorphicAttribute() { } public bool IgnoreUnrecognizedTypeDiscriminators { get { throw null; } set { } } public System.Text.Json.Serialization.JsonUnknownDerivedTypeHandling UnknownDerivedTypeHandling { get { throw null; } set { } } } - [System.AttributeUsageAttribute(System.AttributeTargets.Field | System.AttributeTargets.Property, AllowMultiple=false)] + [System.AttributeUsageAttribute(System.AttributeTargets.Field | System.AttributeTargets.Property, AllowMultiple = false)] public sealed partial class JsonPropertyNameAttribute : System.Text.Json.Serialization.JsonAttribute { public JsonPropertyNameAttribute(string name) { } @@ -900,7 +938,7 @@ public sealed partial class JsonPropertyOrderAttribute : System.Text.Json.Serial public JsonPropertyOrderAttribute(int order) { } public int Order { get { throw null; } } } - [System.AttributeUsageAttribute(System.AttributeTargets.Class, AllowMultiple=true)] + [System.AttributeUsageAttribute(System.AttributeTargets.Class, AllowMultiple = true)] public sealed partial class JsonSerializableAttribute : System.Text.Json.Serialization.JsonAttribute { public JsonSerializableAttribute(System.Type type) { } @@ -914,7 +952,7 @@ protected JsonSerializerContext(System.Text.Json.JsonSerializerOptions? options) public System.Text.Json.JsonSerializerOptions Options { get { throw null; } } public abstract System.Text.Json.Serialization.Metadata.JsonTypeInfo? GetTypeInfo(System.Type type); } - [System.AttributeUsageAttribute(System.AttributeTargets.Class, AllowMultiple=false)] + [System.AttributeUsageAttribute(System.AttributeTargets.Class, AllowMultiple = false)] public sealed partial class JsonSourceGenerationOptionsAttribute : System.Text.Json.Serialization.JsonAttribute { public JsonSourceGenerationOptionsAttribute() { } @@ -938,6 +976,7 @@ public partial class JsonStringEnumConverter : System.Text.Json.Serialization.Js public JsonStringEnumConverter() { } public JsonStringEnumConverter(System.Text.Json.JsonNamingPolicy? namingPolicy = null, bool allowIntegerValues = true) { } public sealed override bool CanConvert(System.Type typeToConvert) { throw null; } + [System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Runtime code generation is not available for Aot form factor.")] public sealed override System.Text.Json.Serialization.JsonConverter CreateConverter(System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) { throw null; } } public enum JsonUnknownDerivedTypeHandling diff --git a/src/libraries/System.Text.Json/ref/System.Text.Json.csproj b/src/libraries/System.Text.Json/ref/System.Text.Json.csproj index fba5fe2ab7af9e..62c80ce3a176c3 100644 --- a/src/libraries/System.Text.Json/ref/System.Text.Json.csproj +++ b/src/libraries/System.Text.Json/ref/System.Text.Json.csproj @@ -23,6 +23,7 @@ + diff --git a/src/libraries/System.Text.Json/src/System.Text.Json.csproj b/src/libraries/System.Text.Json/src/System.Text.Json.csproj index 94386db3989278..a76e54ebc14b0e 100644 --- a/src/libraries/System.Text.Json/src/System.Text.Json.csproj +++ b/src/libraries/System.Text.Json/src/System.Text.Json.csproj @@ -338,6 +338,7 @@ System.Text.Json.Nodes.JsonValue + diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Nodes/JsonArray.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Nodes/JsonArray.cs index 11f214442712f3..ee3ec2855c3fae 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Nodes/JsonArray.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Nodes/JsonArray.cs @@ -99,6 +99,7 @@ internal JsonArray (JsonElement element, JsonNodeOptions? options = null) : base /// The object to be added to the end of the . /// [RequiresUnreferencedCode(JsonValue.CreateUnreferencedCodeMessage)] + [RequiresDynamicCode(JsonValue.CreateUnreferencedCodeMessage)] public void Add(T? value) { if (value == null) diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Nodes/JsonValue.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Nodes/JsonValue.cs index 18700433da605d..fd01f7f2381409 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Nodes/JsonValue.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Nodes/JsonValue.cs @@ -28,6 +28,7 @@ private protected JsonValue(JsonNodeOptions? options = null) : base(options) { } /// Options to control the behavior. /// The new instance of the class that contains the specified value. [RequiresUnreferencedCode(CreateUnreferencedCodeMessage + " Use the overload that takes a JsonTypeInfo, or make sure all of the required types are preserved.")] + [RequiresDynamicCode(CreateUnreferencedCodeMessage + " Use the overload that takes a JsonTypeInfo, or make sure all of the required types are preserved.")] public static JsonValue? Create(T? value, JsonNodeOptions? options = null) { if (value == null) diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Nodes/JsonValueNotTrimmable.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Nodes/JsonValueNotTrimmable.cs index 203ffd7466ab6a..056fccbb3379f7 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Nodes/JsonValueNotTrimmable.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Nodes/JsonValueNotTrimmable.cs @@ -11,10 +11,13 @@ namespace System.Text.Json.Nodes internal sealed partial class JsonValueNotTrimmable : JsonValue { [RequiresUnreferencedCode(JsonSerializer.SerializationUnreferencedCodeMessage)] + [RequiresDynamicCode(JsonSerializer.SerializationRequiresDynamicCodeMessage)] public JsonValueNotTrimmable(TValue value, JsonNodeOptions? options = null) : base(value, options) { } [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "The ctor is marked with RequiresUnreferencedCode.")] + [UnconditionalSuppressMessage("AotAnalysis", "IL3050:RequiresDynamicCode", + Justification = "The ctor is marked with RequiresDynamicCode.")] public override void WriteTo(Utf8JsonWriter writer, JsonSerializerOptions? options = null) { if (writer is null) diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/IAsyncEnumerableConverterFactory.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/IAsyncEnumerableConverterFactory.cs index 840922ae81df2f..6bf1a1a9f2459f 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/IAsyncEnumerableConverterFactory.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/IAsyncEnumerableConverterFactory.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. using System.Collections.Generic; @@ -15,12 +15,15 @@ namespace System.Text.Json.Serialization internal sealed class IAsyncEnumerableConverterFactory : JsonConverterFactory { [RequiresUnreferencedCode(JsonSerializer.SerializationUnreferencedCodeMessage)] + [RequiresDynamicCode(JsonSerializer.SerializationRequiresDynamicCodeMessage)] public IAsyncEnumerableConverterFactory() { } public override bool CanConvert(Type typeToConvert) => GetAsyncEnumerableInterface(typeToConvert) is not null; [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "The ctor is marked RequiresUnreferencedCode.")] + [UnconditionalSuppressMessage("AotAnalysis", "IL3050:RequiresDynamicCode", + Justification = "The ctor is marked with RequiresDynamicCode.")] public override JsonConverter CreateConverter(Type typeToConvert, JsonSerializerOptions options) { Type? asyncEnumerableInterface = GetAsyncEnumerableInterface(typeToConvert); diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/IEnumerableConverterFactory.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/IEnumerableConverterFactory.cs index 976d043d688c5b..462f918c906be1 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/IEnumerableConverterFactory.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/IEnumerableConverterFactory.cs @@ -21,6 +21,7 @@ internal sealed class IEnumerableConverterFactory : JsonConverterFactory private static readonly IListConverter s_converterForIList = new IListConverter(); [RequiresUnreferencedCode(JsonSerializer.SerializationUnreferencedCodeMessage)] + [RequiresDynamicCode(JsonSerializer.SerializationRequiresDynamicCodeMessage)] public IEnumerableConverterFactory() { } public override bool CanConvert(Type typeToConvert) @@ -30,6 +31,8 @@ public override bool CanConvert(Type typeToConvert) [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "The ctor is marked RequiresUnreferencedCode.")] + [UnconditionalSuppressMessage("AotAnalysis", "IL3050:RequiresDynamicCode", + Justification = "The ctor is marked with RequiresDynamicCode.")] public override JsonConverter CreateConverter(Type typeToConvert, JsonSerializerOptions options) { Type converterType; diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/IEnumerableConverterFactoryHelpers.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/IEnumerableConverterFactoryHelpers.cs index d015f7f6a838ee..5db0b9c2f71133 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/IEnumerableConverterFactoryHelpers.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/IEnumerableConverterFactoryHelpers.cs @@ -18,6 +18,7 @@ internal static class IEnumerableConverterFactoryHelpers internal const string ImmutableConvertersUnreferencedCodeMessage = "System.Collections.Immutable converters use Reflection to find and create Immutable Collection types, which requires unreferenced code."; [RequiresUnreferencedCode(ImmutableConvertersUnreferencedCodeMessage)] + [RequiresDynamicCode(ImmutableConvertersUnreferencedCodeMessage)] public static MethodInfo GetImmutableEnumerableCreateRangeMethod(this Type type, Type elementType) { Type? constructingType = GetImmutableEnumerableConstructingType(type); @@ -41,6 +42,7 @@ public static MethodInfo GetImmutableEnumerableCreateRangeMethod(this Type type, } [RequiresUnreferencedCode(ImmutableConvertersUnreferencedCodeMessage)] + [RequiresDynamicCode(ImmutableConvertersUnreferencedCodeMessage)] public static MethodInfo GetImmutableDictionaryCreateRangeMethod(this Type type, Type keyType, Type valueType) { Type? constructingType = GetImmutableDictionaryConstructingType(type); @@ -64,6 +66,7 @@ public static MethodInfo GetImmutableDictionaryCreateRangeMethod(this Type type, } [RequiresUnreferencedCode(ImmutableConvertersUnreferencedCodeMessage)] + [RequiresDynamicCode(ImmutableConvertersUnreferencedCodeMessage)] private static Type? GetImmutableEnumerableConstructingType(Type type) { Debug.Assert(type.IsImmutableEnumerableType()); @@ -76,6 +79,7 @@ public static MethodInfo GetImmutableDictionaryCreateRangeMethod(this Type type, } [RequiresUnreferencedCode(ImmutableConvertersUnreferencedCodeMessage)] + [RequiresDynamicCode(ImmutableConvertersUnreferencedCodeMessage)] private static Type? GetImmutableDictionaryConstructingType(Type type) { Debug.Assert(type.IsImmutableDictionaryType()); diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/ImmutableDictionaryOfTKeyTValueConverterWithReflection.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/ImmutableDictionaryOfTKeyTValueConverterWithReflection.cs index e9ab9029d7caba..a5ca43d82f4d95 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/ImmutableDictionaryOfTKeyTValueConverterWithReflection.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/ImmutableDictionaryOfTKeyTValueConverterWithReflection.cs @@ -14,11 +14,13 @@ internal sealed class ImmutableDictionaryOfTKeyTValueConverterWithReflection(); diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/ImmutableEnumerableOfTConverterWithReflection.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/ImmutableEnumerableOfTConverterWithReflection.cs index a3efc00817a7de..d7111490e4c278 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/ImmutableEnumerableOfTConverterWithReflection.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/ImmutableEnumerableOfTConverterWithReflection.cs @@ -13,11 +13,13 @@ internal sealed class ImmutableEnumerableOfTConverterWithReflection { [RequiresUnreferencedCode(IEnumerableConverterFactoryHelpers.ImmutableConvertersUnreferencedCodeMessage)] + [RequiresDynamicCode(IEnumerableConverterFactoryHelpers.ImmutableConvertersUnreferencedCodeMessage)] public ImmutableEnumerableOfTConverterWithReflection() { } [RequiresUnreferencedCode(IEnumerableConverterFactoryHelpers.ImmutableConvertersUnreferencedCodeMessage)] + [RequiresDynamicCode(IEnumerableConverterFactoryHelpers.ImmutableConvertersUnreferencedCodeMessage)] internal override void ConfigureJsonTypeInfoUsingReflection(JsonTypeInfo jsonTypeInfo, JsonSerializerOptions options) { jsonTypeInfo.CreateObjectWithArgs = options.MemberAccessorStrategy.CreateImmutableEnumerableCreateRangeDelegate(); diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/StackOrQueueConverterWithReflection.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/StackOrQueueConverterWithReflection.cs index c5bc4144f8a777..e89716315154b8 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/StackOrQueueConverterWithReflection.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/StackOrQueueConverterWithReflection.cs @@ -13,9 +13,11 @@ internal sealed class StackOrQueueConverterWithReflection where TCollection : IEnumerable { [RequiresUnreferencedCode(JsonSerializer.SerializationUnreferencedCodeMessage)] + [RequiresDynamicCode(JsonSerializer.SerializationRequiresDynamicCodeMessage)] public StackOrQueueConverterWithReflection() { } [RequiresUnreferencedCode(JsonSerializer.SerializationUnreferencedCodeMessage)] + [RequiresDynamicCode(JsonSerializer.SerializationRequiresDynamicCodeMessage)] internal override void ConfigureJsonTypeInfoUsingReflection(JsonTypeInfo jsonTypeInfo, JsonSerializerOptions options) { jsonTypeInfo.AddMethodDelegate = options.MemberAccessorStrategy.CreateAddMethodDelegate(); diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/FSharp/FSharpListConverter.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/FSharp/FSharpListConverter.cs index fe5249e5360daf..f65f2448eee27c 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/FSharp/FSharpListConverter.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/FSharp/FSharpListConverter.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. using System.Collections.Generic; @@ -14,6 +14,7 @@ internal sealed class FSharpListConverter : IEnumerableDefaultC private readonly Func, TList> _listConstructor; [RequiresUnreferencedCode(FSharpCoreReflectionProxy.FSharpCoreUnreferencedCodeMessage)] + [RequiresDynamicCode(FSharpCoreReflectionProxy.FSharpCoreUnreferencedCodeMessage)] public FSharpListConverter() { _listConstructor = FSharpCoreReflectionProxy.Instance.CreateFSharpListConstructor(); diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/FSharp/FSharpMapConverter.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/FSharp/FSharpMapConverter.cs index ba3b0b7b2f1d55..af2a6f4cae6185 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/FSharp/FSharpMapConverter.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/FSharp/FSharpMapConverter.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. using System.Collections.Generic; @@ -15,6 +15,7 @@ internal sealed class FSharpMapConverter : DictionaryDefault private readonly Func>, TMap> _mapConstructor; [RequiresUnreferencedCode(FSharpCoreReflectionProxy.FSharpCoreUnreferencedCodeMessage)] + [RequiresDynamicCode(FSharpCoreReflectionProxy.FSharpCoreUnreferencedCodeMessage)] public FSharpMapConverter() { _mapConstructor = FSharpCoreReflectionProxy.Instance.CreateFSharpMapConstructor(); diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/FSharp/FSharpOptionConverter.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/FSharp/FSharpOptionConverter.cs index 9614e8492a52dc..c0ba55e63d2a49 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/FSharp/FSharpOptionConverter.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/FSharp/FSharpOptionConverter.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. using System.Diagnostics.CodeAnalysis; @@ -23,6 +23,7 @@ internal sealed class FSharpOptionConverter : JsonConverter elementConverter) { _elementConverter = elementConverter; diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/FSharp/FSharpSetConverter.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/FSharp/FSharpSetConverter.cs index 0d41243e241024..86a20f2948ab5c 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/FSharp/FSharpSetConverter.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/FSharp/FSharpSetConverter.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. using System.Collections.Generic; @@ -14,6 +14,7 @@ internal sealed class FSharpSetConverter : IEnumerableDefaultCon private readonly Func, TSet> _setConstructor; [RequiresUnreferencedCode(FSharpCoreReflectionProxy.FSharpCoreUnreferencedCodeMessage)] + [RequiresDynamicCode(FSharpCoreReflectionProxy.FSharpCoreUnreferencedCodeMessage)] public FSharpSetConverter() { _setConstructor = FSharpCoreReflectionProxy.Instance.CreateFSharpSetConstructor(); diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/FSharp/FSharpTypeConverterFactory.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/FSharp/FSharpTypeConverterFactory.cs index 54f6ce3eacfe45..ef130d1f9fe448 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/FSharp/FSharpTypeConverterFactory.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/FSharp/FSharpTypeConverterFactory.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. using System.Diagnostics; @@ -11,18 +11,23 @@ namespace System.Text.Json.Serialization.Converters internal sealed class FSharpTypeConverterFactory : JsonConverterFactory { [RequiresUnreferencedCode(FSharpCoreReflectionProxy.FSharpCoreUnreferencedCodeMessage)] + [RequiresDynamicCode(FSharpCoreReflectionProxy.FSharpCoreUnreferencedCodeMessage)] public FSharpTypeConverterFactory() { } private ObjectConverterFactory? _recordConverterFactory; [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "The ctor is marked with RequiresUnreferencedCode.")] + [UnconditionalSuppressMessage("AotAnalysis", "IL3050:RequiresDynamicCode", + Justification = "The ctor is marked with RequiresDynamicCode.")] public override bool CanConvert(Type typeToConvert) => FSharpCoreReflectionProxy.IsFSharpType(typeToConvert) && FSharpCoreReflectionProxy.Instance.DetectFSharpKind(typeToConvert) is not FSharpKind.Unrecognized; [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "The ctor is marked with RequiresUnreferencedCode.")] + [UnconditionalSuppressMessage("AotAnalysis", "IL3050:RequiresDynamicCode", + Justification = "The ctor is marked with RequiresDynamicCode.")] public override JsonConverter? CreateConverter(Type typeToConvert, JsonSerializerOptions options) { Debug.Assert(CanConvert(typeToConvert)); diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/FSharp/FSharpValueOptionConverter.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/FSharp/FSharpValueOptionConverter.cs index ccafcdf180e1b6..1c147c4b640696 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/FSharp/FSharpValueOptionConverter.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/FSharp/FSharpValueOptionConverter.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. using System.Diagnostics.CodeAnalysis; @@ -23,6 +23,7 @@ internal sealed class FSharpValueOptionConverter : JsonC private readonly ConverterStrategy _converterStrategy; [RequiresUnreferencedCode(FSharpCoreReflectionProxy.FSharpCoreUnreferencedCodeMessage)] + [RequiresDynamicCode(FSharpCoreReflectionProxy.FSharpCoreUnreferencedCodeMessage)] public FSharpValueOptionConverter(JsonConverter elementConverter) { _elementConverter = elementConverter; diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Object/ObjectConverterFactory.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Object/ObjectConverterFactory.cs index 52dc1c6dd9800b..22bf7962296fad 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Object/ObjectConverterFactory.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Object/ObjectConverterFactory.cs @@ -19,6 +19,7 @@ internal sealed class ObjectConverterFactory : JsonConverterFactory private readonly bool _useDefaultConstructorInUnannotatedStructs; [RequiresUnreferencedCode(JsonSerializer.SerializationUnreferencedCodeMessage)] + [RequiresDynamicCode(JsonSerializer.SerializationRequiresDynamicCodeMessage)] public ObjectConverterFactory(bool useDefaultConstructorInUnannotatedStructs = true) { _useDefaultConstructorInUnannotatedStructs = useDefaultConstructorInUnannotatedStructs; @@ -36,6 +37,8 @@ public override bool CanConvert(Type typeToConvert) Justification = "The ctor is marked RequiresUnreferencedCode.")] [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2067:UnrecognizedReflectionPattern", Justification = "The ctor is marked RequiresUnreferencedCode.")] + [UnconditionalSuppressMessage("AotAnalysis", "IL3050:RequiresDynamicCode", + Justification = "The ctor is marked with RequiresDynamicCode.")] public override JsonConverter CreateConverter(Type typeToConvert, JsonSerializerOptions options) { if (typeToConvert.IsKeyValuePair()) @@ -99,6 +102,7 @@ public override JsonConverter CreateConverter(Type typeToConvert, JsonSerializer return converter; } + [RequiresDynamicCode(JsonSerializer.SerializationRequiresDynamicCodeMessage)] private static JsonConverter CreateKeyValuePairConverter(Type type) { Debug.Assert(type.IsKeyValuePair()); diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Object/ObjectWithParameterizedConstructorConverter.Large.Reflection.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Object/ObjectWithParameterizedConstructorConverter.Large.Reflection.cs index 351f7e4895ff8e..3361881b3c239a 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Object/ObjectWithParameterizedConstructorConverter.Large.Reflection.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Object/ObjectWithParameterizedConstructorConverter.Large.Reflection.cs @@ -15,11 +15,13 @@ internal sealed class LargeObjectWithParameterizedConstructorConverterWithReflec : LargeObjectWithParameterizedConstructorConverter where T : notnull { [RequiresUnreferencedCode(JsonSerializer.SerializationUnreferencedCodeMessage)] + [RequiresDynamicCode(JsonSerializer.SerializationRequiresDynamicCodeMessage)] public LargeObjectWithParameterizedConstructorConverterWithReflection() { } [RequiresUnreferencedCode(JsonSerializer.SerializationUnreferencedCodeMessage)] + [RequiresDynamicCode(JsonSerializer.SerializationRequiresDynamicCodeMessage)] internal override void ConfigureJsonTypeInfoUsingReflection(JsonTypeInfo jsonTypeInfo, JsonSerializerOptions options) { jsonTypeInfo.CreateObjectWithArgs = options.MemberAccessorStrategy.CreateParameterizedConstructor(ConstructorInfo!); diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/EnumConverterFactory.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/EnumConverterFactory.cs index 6820a1ca9afcd4..4cd989677fed6b 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/EnumConverterFactory.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/EnumConverterFactory.cs @@ -29,6 +29,8 @@ internal static JsonConverter Create(Type enumType, EnumConverterOptions convert [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2055:MakeGenericType", Justification = "'EnumConverter where T : struct' implies 'T : new()', so the trimmer is warning calling MakeGenericType here because enumType's constructors are not annotated. " + "But EnumConverter doesn't call new T(), so this is safe.")] + [UnconditionalSuppressMessage("AotAnalysis", "IL3050:RequiresDynamicCode", Justification = "The factory constructors are only invoked in the context of reflection serialization code paths " + + "and are marked with 'RequiresDynamicCode'")] [return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] private static Type GetEnumConverterType(Type enumType) => typeof(EnumConverter<>).MakeGenericType(enumType); } diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/NullableConverterFactory.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/NullableConverterFactory.cs index 469205e4d99f6c..651c981fc0950b 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/NullableConverterFactory.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/NullableConverterFactory.cs @@ -46,6 +46,8 @@ public static JsonConverter CreateValueConverter(Type valueTypeToConvert, JsonCo [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2055:MakeGenericType", Justification = "'NullableConverter where T : struct' implies 'T : new()', so the trimmer is warning calling MakeGenericType here because valueTypeToConvert's constructors are not annotated. " + "But NullableConverter doesn't call new T(), so this is safe.")] + [UnconditionalSuppressMessage("AotAnalysis", "IL3050:RequiresDynamicCode", Justification = "The factory constructors are only invoked in the context of reflection serialization code paths " + + "and are marked with 'RequiresDynamicCode'")] [return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] private static Type GetNullableConverterType(Type valueTypeToConvert) => typeof(NullableConverter<>).MakeGenericType(valueTypeToConvert); } diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/UnsupportedTypeConverterFactory.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/UnsupportedTypeConverterFactory.cs index 970dfc781085bc..499555147a21d0 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/UnsupportedTypeConverterFactory.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/UnsupportedTypeConverterFactory.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using System.Diagnostics.CodeAnalysis; using System.Reflection; using System.Runtime.Serialization; @@ -40,6 +41,8 @@ public override bool CanConvert(Type type) #endif } + [UnconditionalSuppressMessage("AotAnalysis", "IL3050:RequiresDynamicCode", Justification = "The factory constructors are only invoked in the context of reflection serialization code paths " + + "and are marked with 'RequiresDynamicCode'")] public override JsonConverter CreateConverter(Type type, JsonSerializerOptions options) { JsonConverter converter = (JsonConverter)Activator.CreateInstance( diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonConverter.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonConverter.cs index 1f2ea53ee88b33..fd6acba560a818 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonConverter.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonConverter.cs @@ -132,6 +132,7 @@ internal virtual void ConfigureJsonTypeInfo(JsonTypeInfo jsonTypeInfo, JsonSeria /// Additional reflection-specific configuration required by certain collection converters. /// [RequiresUnreferencedCode(JsonSerializer.SerializationUnreferencedCodeMessage)] + [RequiresDynamicCode(JsonSerializer.SerializationRequiresDynamicCodeMessage)] internal virtual void ConfigureJsonTypeInfoUsingReflection(JsonTypeInfo jsonTypeInfo, JsonSerializerOptions options) { } } } diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Helpers.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Helpers.cs index 71686187483625..de4c61f0614c36 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Helpers.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Helpers.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. using System.Diagnostics; @@ -11,8 +11,10 @@ namespace System.Text.Json public static partial class JsonSerializer { internal const string SerializationUnreferencedCodeMessage = "JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved."; + internal const string SerializationRequiresDynamicCodeMessage = "JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use source generated paths for native aot applications."; [RequiresUnreferencedCode(SerializationUnreferencedCodeMessage)] + [RequiresDynamicCode(SerializationRequiresDynamicCodeMessage)] private static JsonTypeInfo GetTypeInfo(JsonSerializerOptions? options, Type runtimeType) { Debug.Assert(runtimeType != null); diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.Document.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.Document.cs index b6afa9185b16ae..f49d96e04c23d6 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.Document.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.Document.cs @@ -27,6 +27,7 @@ public static partial class JsonSerializer /// for or its serializable members. /// [RequiresUnreferencedCode(SerializationUnreferencedCodeMessage)] + [RequiresDynamicCode(SerializationRequiresDynamicCodeMessage)] public static TValue? Deserialize(this JsonDocument document, JsonSerializerOptions? options = null) { if (document is null) @@ -56,6 +57,7 @@ public static partial class JsonSerializer /// for or its serializable members. /// [RequiresUnreferencedCode(SerializationUnreferencedCodeMessage)] + [RequiresDynamicCode(SerializationRequiresDynamicCodeMessage)] public static object? Deserialize(this JsonDocument document, Type returnType, JsonSerializerOptions? options = null) { if (document is null) diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.Element.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.Element.cs index 5b03983f726885..f9cd108c47dccf 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.Element.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.Element.cs @@ -24,6 +24,7 @@ public static partial class JsonSerializer /// for or its serializable members. /// [RequiresUnreferencedCode(SerializationUnreferencedCodeMessage)] + [RequiresDynamicCode(SerializationRequiresDynamicCodeMessage)] public static TValue? Deserialize(this JsonElement element, JsonSerializerOptions? options = null) { JsonTypeInfo jsonTypeInfo = GetTypeInfo(options, typeof(TValue)); @@ -48,6 +49,7 @@ public static partial class JsonSerializer /// for or its serializable members. /// [RequiresUnreferencedCode(SerializationUnreferencedCodeMessage)] + [RequiresDynamicCode(SerializationRequiresDynamicCodeMessage)] public static object? Deserialize(this JsonElement element, Type returnType, JsonSerializerOptions? options = null) { if (returnType is null) diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.Node.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.Node.cs index e15dcf7c32b0c3..08f770349dac80 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.Node.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.Node.cs @@ -26,6 +26,7 @@ public static partial class JsonSerializer /// for or its serializable members. /// [RequiresUnreferencedCode(SerializationUnreferencedCodeMessage)] + [RequiresDynamicCode(SerializationRequiresDynamicCodeMessage)] public static TValue? Deserialize(this JsonNode? node, JsonSerializerOptions? options = null) { JsonTypeInfo jsonTypeInfo = GetTypeInfo(options, typeof(TValue)); @@ -47,6 +48,7 @@ public static partial class JsonSerializer /// for or its serializable members. /// [RequiresUnreferencedCode(SerializationUnreferencedCodeMessage)] + [RequiresDynamicCode(SerializationRequiresDynamicCodeMessage)] public static object? Deserialize(this JsonNode? node, Type returnType, JsonSerializerOptions? options = null) { if (returnType is null) diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.Span.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.Span.cs index 414b9033001768..8708f4a92debd9 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.Span.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.Span.cs @@ -26,6 +26,7 @@ public static partial class JsonSerializer /// for or its serializable members. /// [RequiresUnreferencedCode(SerializationUnreferencedCodeMessage)] + [RequiresDynamicCode(SerializationRequiresDynamicCodeMessage)] public static TValue? Deserialize(ReadOnlySpan utf8Json, JsonSerializerOptions? options = null) { JsonTypeInfo jsonTypeInfo = GetTypeInfo(options, typeof(TValue)); @@ -52,6 +53,7 @@ public static partial class JsonSerializer /// for or its serializable members. /// [RequiresUnreferencedCode(SerializationUnreferencedCodeMessage)] + [RequiresDynamicCode(SerializationRequiresDynamicCodeMessage)] public static object? Deserialize(ReadOnlySpan utf8Json, Type returnType, JsonSerializerOptions? options = null) { if (returnType is null) diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.Stream.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.Stream.cs index ae5ba364afd47e..7d3fa526bc80ad 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.Stream.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.Stream.cs @@ -41,6 +41,7 @@ public static partial class JsonSerializer /// for or its serializable members. /// [RequiresUnreferencedCode(SerializationUnreferencedCodeMessage)] + [RequiresDynamicCode(SerializationRequiresDynamicCodeMessage)] public static ValueTask DeserializeAsync( Stream utf8Json, JsonSerializerOptions? options = null, @@ -76,6 +77,7 @@ public static partial class JsonSerializer /// for or its serializable members. /// [RequiresUnreferencedCode(SerializationUnreferencedCodeMessage)] + [RequiresDynamicCode(SerializationRequiresDynamicCodeMessage)] public static TValue? Deserialize( Stream utf8Json, JsonSerializerOptions? options = null) @@ -112,6 +114,7 @@ public static partial class JsonSerializer /// for or its serializable members. /// [RequiresUnreferencedCode(SerializationUnreferencedCodeMessage)] + [RequiresDynamicCode(SerializationRequiresDynamicCodeMessage)] public static ValueTask DeserializeAsync( Stream utf8Json, Type returnType, @@ -152,6 +155,7 @@ public static partial class JsonSerializer /// for or its serializable members. /// [RequiresUnreferencedCode(SerializationUnreferencedCodeMessage)] + [RequiresDynamicCode(SerializationRequiresDynamicCodeMessage)] public static object? Deserialize( Stream utf8Json, Type returnType, @@ -353,6 +357,7 @@ public static partial class JsonSerializer /// is . /// [RequiresUnreferencedCode(SerializationUnreferencedCodeMessage)] + [RequiresDynamicCode(SerializationRequiresDynamicCodeMessage)] public static IAsyncEnumerable DeserializeAsyncEnumerable( Stream utf8Json, JsonSerializerOptions? options = null, @@ -372,6 +377,7 @@ public static partial class JsonSerializer return CreateAsyncEnumerableDeserializer(utf8Json, options, cancellationToken); [RequiresUnreferencedCode(SerializationUnreferencedCodeMessage)] + [RequiresDynamicCode(SerializationRequiresDynamicCodeMessage)] static async IAsyncEnumerable CreateAsyncEnumerableDeserializer( Stream utf8Json, JsonSerializerOptions options, @@ -411,6 +417,7 @@ static async IAsyncEnumerable CreateAsyncEnumerableDeserializer( [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "Workaround for https://github.com/mono/linker/issues/1416. All usages are marked as unsafe.")] + [RequiresDynamicCode(SerializationRequiresDynamicCodeMessage)] private static JsonTypeInfo CreateQueueJsonTypeInfo(JsonConverter queueConverter, JsonSerializerOptions queueOptions) => new ReflectionJsonTypeInfo>(queueConverter, queueOptions); @@ -622,6 +629,7 @@ internal static TValue ContinueDeserialize( } [RequiresUnreferencedCode(SerializationUnreferencedCodeMessage)] + [RequiresDynamicCode(SerializationRequiresDynamicCodeMessage)] private static TValue? ReadAllUsingOptions( Stream utf8Json, Type returnType, diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.String.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.String.cs index 4aff8fae0f0202..e9bb1f1069d41a 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.String.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.String.cs @@ -42,6 +42,7 @@ public static partial class JsonSerializer /// UTF-8 methods since the implementation natively uses UTF-8. /// [RequiresUnreferencedCode(SerializationUnreferencedCodeMessage)] + [RequiresDynamicCode(SerializationRequiresDynamicCodeMessage)] public static TValue? Deserialize([StringSyntax(StringSyntaxAttribute.Json)] string json, JsonSerializerOptions? options = null) { if (json is null) @@ -78,6 +79,7 @@ public static partial class JsonSerializer /// UTF-8 methods since the implementation natively uses UTF-8. /// [RequiresUnreferencedCode(SerializationUnreferencedCodeMessage)] + [RequiresDynamicCode(SerializationRequiresDynamicCodeMessage)] public static TValue? Deserialize([StringSyntax(StringSyntaxAttribute.Json)] ReadOnlySpan json, JsonSerializerOptions? options = null) { // default/null span is treated as empty @@ -114,6 +116,7 @@ public static partial class JsonSerializer /// UTF-8 methods since the implementation natively uses UTF-8. /// [RequiresUnreferencedCode(SerializationUnreferencedCodeMessage)] + [RequiresDynamicCode(SerializationRequiresDynamicCodeMessage)] public static object? Deserialize([StringSyntax(StringSyntaxAttribute.Json)] string json, Type returnType, JsonSerializerOptions? options = null) { if (json is null) @@ -157,6 +160,7 @@ public static partial class JsonSerializer /// UTF-8 methods since the implementation natively uses UTF-8. /// [RequiresUnreferencedCode(SerializationUnreferencedCodeMessage)] + [RequiresDynamicCode(SerializationRequiresDynamicCodeMessage)] public static object? Deserialize([StringSyntax(StringSyntaxAttribute.Json)] ReadOnlySpan json, Type returnType, JsonSerializerOptions? options = null) { if (returnType is null) diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.Utf8JsonReader.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.Utf8JsonReader.cs index 5e5697cde4605b..d98fd97672bdb4 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.Utf8JsonReader.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.Utf8JsonReader.cs @@ -55,6 +55,7 @@ public static partial class JsonSerializer /// /// [RequiresUnreferencedCode(SerializationUnreferencedCodeMessage)] + [RequiresDynamicCode(SerializationRequiresDynamicCodeMessage)] public static TValue? Deserialize(ref Utf8JsonReader reader, JsonSerializerOptions? options = null) { JsonTypeInfo jsonTypeInfo = GetTypeInfo(options, typeof(TValue)); @@ -107,6 +108,7 @@ public static partial class JsonSerializer /// /// [RequiresUnreferencedCode(SerializationUnreferencedCodeMessage)] + [RequiresDynamicCode(SerializationRequiresDynamicCodeMessage)] public static object? Deserialize(ref Utf8JsonReader reader, Type returnType, JsonSerializerOptions? options = null) { if (returnType is null) diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Write.ByteArray.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Write.ByteArray.cs index 532a00349b3cfe..dda1088e7acf99 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Write.ByteArray.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Write.ByteArray.cs @@ -20,6 +20,7 @@ public static partial class JsonSerializer /// for or its serializable members. /// [RequiresUnreferencedCode(SerializationUnreferencedCodeMessage)] + [RequiresDynamicCode(SerializationRequiresDynamicCodeMessage)] public static byte[] SerializeToUtf8Bytes( TValue value, JsonSerializerOptions? options = null) @@ -47,6 +48,7 @@ public static byte[] SerializeToUtf8Bytes( /// for or its serializable members. /// [RequiresUnreferencedCode(SerializationUnreferencedCodeMessage)] + [RequiresDynamicCode(SerializationRequiresDynamicCodeMessage)] public static byte[] SerializeToUtf8Bytes( object? value, Type inputType, diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Write.Document.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Write.Document.cs index 2be92327890a4f..731dd0b46cb4a0 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Write.Document.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Write.Document.cs @@ -22,6 +22,7 @@ public static partial class JsonSerializer /// for or its serializable members. /// [RequiresUnreferencedCode(SerializationUnreferencedCodeMessage)] + [RequiresDynamicCode(SerializationRequiresDynamicCodeMessage)] public static JsonDocument SerializeToDocument(TValue value, JsonSerializerOptions? options = null) { Type runtimeType = GetRuntimeType(value); @@ -47,6 +48,7 @@ public static JsonDocument SerializeToDocument(TValue value, JsonSeriali /// for or its serializable members. /// [RequiresUnreferencedCode(SerializationUnreferencedCodeMessage)] + [RequiresDynamicCode(SerializationRequiresDynamicCodeMessage)] public static JsonDocument SerializeToDocument(object? value, Type inputType, JsonSerializerOptions? options = null) { Type runtimeType = GetRuntimeTypeAndValidateInputType(value, inputType); diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Write.Element.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Write.Element.cs index 0aeb8bbf84b451..3343f544a1c11f 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Write.Element.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Write.Element.cs @@ -22,6 +22,7 @@ public static partial class JsonSerializer /// for or its serializable members. /// [RequiresUnreferencedCode(SerializationUnreferencedCodeMessage)] + [RequiresDynamicCode(SerializationRequiresDynamicCodeMessage)] public static JsonElement SerializeToElement(TValue value, JsonSerializerOptions? options = null) { Type runtimeType = GetRuntimeType(value); @@ -47,6 +48,7 @@ public static JsonElement SerializeToElement(TValue value, JsonSerialize /// for or its serializable members. /// [RequiresUnreferencedCode(SerializationUnreferencedCodeMessage)] + [RequiresDynamicCode(SerializationRequiresDynamicCodeMessage)] public static JsonElement SerializeToElement(object? value, Type inputType, JsonSerializerOptions? options = null) { Type runtimeType = GetRuntimeTypeAndValidateInputType(value, inputType); diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Write.Node.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Write.Node.cs index 2360c4618794ff..3676bc1c4afe76 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Write.Node.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Write.Node.cs @@ -23,6 +23,7 @@ public static partial class JsonSerializer /// for or its serializable members. /// [RequiresUnreferencedCode(SerializationUnreferencedCodeMessage)] + [RequiresDynamicCode(SerializationRequiresDynamicCodeMessage)] public static JsonNode? SerializeToNode(TValue value, JsonSerializerOptions? options = null) { Type runtimeType = GetRuntimeType(value); @@ -48,6 +49,7 @@ public static partial class JsonSerializer /// for or its serializable members. /// [RequiresUnreferencedCode(SerializationUnreferencedCodeMessage)] + [RequiresDynamicCode(SerializationRequiresDynamicCodeMessage)] public static JsonNode? SerializeToNode(object? value, Type inputType, JsonSerializerOptions? options = null) { Type runtimeType = GetRuntimeTypeAndValidateInputType(value, inputType); diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Write.Stream.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Write.Stream.cs index 3ddc473800d09e..9fb7c5c8394218 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Write.Stream.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Write.Stream.cs @@ -38,6 +38,7 @@ public static partial class JsonSerializer /// for or its serializable members. /// [RequiresUnreferencedCode(SerializationUnreferencedCodeMessage)] + [RequiresDynamicCode(SerializationRequiresDynamicCodeMessage)] public static Task SerializeAsync( Stream utf8Json, TValue value, @@ -69,6 +70,7 @@ public static Task SerializeAsync( /// for or its serializable members. /// [RequiresUnreferencedCode(SerializationUnreferencedCodeMessage)] + [RequiresDynamicCode(SerializationRequiresDynamicCodeMessage)] public static void Serialize( Stream utf8Json, TValue value, @@ -104,6 +106,7 @@ public static void Serialize( /// for or its serializable members. /// [RequiresUnreferencedCode(SerializationUnreferencedCodeMessage)] + [RequiresDynamicCode(SerializationRequiresDynamicCodeMessage)] public static Task SerializeAsync( Stream utf8Json, object? value, @@ -139,6 +142,7 @@ public static Task SerializeAsync( /// for or its serializable members. /// [RequiresUnreferencedCode(SerializationUnreferencedCodeMessage)] + [RequiresDynamicCode(SerializationRequiresDynamicCodeMessage)] public static void Serialize( Stream utf8Json, object? value, diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Write.String.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Write.String.cs index a63fb0566251aa..674a3063956c70 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Write.String.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Write.String.cs @@ -25,6 +25,7 @@ public static partial class JsonSerializer /// and . /// [RequiresUnreferencedCode(SerializationUnreferencedCodeMessage)] + [RequiresDynamicCode(SerializationRequiresDynamicCodeMessage)] public static string Serialize(TValue value, JsonSerializerOptions? options = null) { Type runtimeType = GetRuntimeType(value); @@ -54,6 +55,7 @@ public static string Serialize(TValue value, JsonSerializerOptions? opti /// and . /// [RequiresUnreferencedCode(SerializationUnreferencedCodeMessage)] + [RequiresDynamicCode(SerializationRequiresDynamicCodeMessage)] public static string Serialize( object? value, Type inputType, diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Write.Utf8JsonWriter.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Write.Utf8JsonWriter.cs index bdd50066c0e647..7f27dcdd50a2eb 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Write.Utf8JsonWriter.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Write.Utf8JsonWriter.cs @@ -24,6 +24,7 @@ public static partial class JsonSerializer /// for or its serializable members. /// [RequiresUnreferencedCode(SerializationUnreferencedCodeMessage)] + [RequiresDynamicCode(SerializationRequiresDynamicCodeMessage)] public static void Serialize( Utf8JsonWriter writer, TValue value, @@ -57,6 +58,7 @@ public static void Serialize( /// for or its serializable members. /// [RequiresUnreferencedCode(SerializationUnreferencedCodeMessage)] + [RequiresDynamicCode(SerializationRequiresDynamicCodeMessage)] public static void Serialize( Utf8JsonWriter writer, object? value, diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializerOptions.Converters.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializerOptions.Converters.cs index 91b7d7433214b4..8de6c2f73f7356 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializerOptions.Converters.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializerOptions.Converters.cs @@ -29,6 +29,7 @@ public sealed partial class JsonSerializerOptions private static Func? s_typeInfoCreationFunc; [RequiresUnreferencedCode(JsonSerializer.SerializationUnreferencedCodeMessage)] + [RequiresDynamicCode(JsonSerializer.SerializationRequiresDynamicCodeMessage)] private static void RootReflectionSerializerDependencies() { // s_typeInfoCreationFunc is the last field assigned. @@ -42,6 +43,7 @@ private static void RootReflectionSerializerDependencies() } [RequiresUnreferencedCode(JsonSerializer.SerializationUnreferencedCodeMessage)] + [RequiresDynamicCode(JsonSerializer.SerializationRequiresDynamicCodeMessage)] static JsonTypeInfo CreateJsonTypeInfo(Type type, JsonSerializerOptions options) { JsonTypeInfo.ValidateType(type, null, null, options); @@ -66,12 +68,14 @@ static JsonTypeInfo CreateJsonTypeInfo(Type type, JsonSerializerOptions options) } [RequiresUnreferencedCode(JsonSerializer.SerializationUnreferencedCodeMessage)] + [RequiresDynamicCode(JsonSerializer.SerializationRequiresDynamicCodeMessage)] private JsonTypeInfo CreateReflectionJsonTypeInfo() { return new ReflectionJsonTypeInfo(this); } [RequiresUnreferencedCode(JsonSerializer.SerializationUnreferencedCodeMessage)] + [RequiresDynamicCode(JsonSerializer.SerializationRequiresDynamicCodeMessage)] private static JsonConverter[] GetDefaultFactoryConverters() { return new JsonConverter[] @@ -212,6 +216,7 @@ internal JsonConverter GetConverterFromMember(Type? parentClassType, Type proper /// for or its serializable members. /// [RequiresUnreferencedCode("Getting a converter for a type may require reflection which depends on unreferenced code.")] + [RequiresDynamicCode("Getting a converter for a type may require reflection which depends on unreferenced code.")] public JsonConverter GetConverter(Type typeToConvert) { if (typeToConvert is null) diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializerOptions.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializerOptions.cs index 32e3d2b2a29885..3a73a328952cc9 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializerOptions.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializerOptions.cs @@ -571,7 +571,7 @@ internal JsonSerializerContext? JsonSerializerContext // The cached value used to determine if ReferenceHandler should use Preserve or IgnoreCycles semanitcs or None of them. internal ReferenceHandlingStrategy ReferenceHandlingStrategy = ReferenceHandlingStrategy.None; - + [UnconditionalSuppressMessage("AotAnalysis", "IL3050:RequiresDynamicCode", Justification = "Dyanmic path is guarded by the the runtime feature switch.")] internal MemberAccessor MemberAccessorStrategy { get @@ -604,6 +604,7 @@ internal MemberAccessor MemberAccessorStrategy /// must be checked before calling. /// [RequiresUnreferencedCode(JsonSerializer.SerializationUnreferencedCodeMessage)] + [RequiresDynamicCode(JsonSerializer.SerializationRequiresDynamicCodeMessage)] internal void InitializeForReflectionSerializer() { RootReflectionSerializerDependencies(); diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializerOptionsUpdateHandler.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializerOptionsUpdateHandler.cs index 4fd3c66edae085..2b037a1a4cba61 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializerOptionsUpdateHandler.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializerOptionsUpdateHandler.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Reflection.Metadata; using System.Text.Json; using System.Text.Json.Serialization.Metadata; @@ -13,6 +14,7 @@ namespace System.Text.Json /// Handler used to clear JsonSerializerOptions reflection cache upon a metadata update. internal static class JsonSerializerOptionsUpdateHandler { + [RequiresDynamicCode("Runtime code generation is not available for Aot form factor.")] public static void ClearCache(Type[]? types) { // Ignore the types, and just clear out all reflection caches from serializer options. diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonStringEnumConverter.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonStringEnumConverter.cs index 7d8d161acd0a35..bb05a877151b0f 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonStringEnumConverter.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonStringEnumConverter.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using System.Diagnostics.CodeAnalysis; using System.Text.Json.Serialization.Converters; namespace System.Text.Json.Serialization @@ -51,6 +52,8 @@ public sealed override bool CanConvert(Type typeToConvert) } /// + [RequiresDynamicCode("Runtime code generation is not available for Aot form factor.")] + [SuppressMessage("AotAnalysis", "IL3051:'RequiresDynamicCodeAttribute' annotations must match across all interface implementations or overrides.", Justification = "Suppressing base type warnings")] public sealed override JsonConverter CreateConverter(Type typeToConvert, JsonSerializerOptions options) => EnumConverterFactory.Create(typeToConvert, _converterOptions, _namingPolicy, options); } diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/FSharpCoreReflectionProxy.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/FSharpCoreReflectionProxy.cs index 6962bd011d9263..e0bd83a0c1c9bf 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/FSharpCoreReflectionProxy.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/FSharpCoreReflectionProxy.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. using System.Collections.Generic; @@ -61,6 +61,7 @@ public enum FSharpKind /// If true, also initializes the proxy singleton for future by other F# types. /// [RequiresUnreferencedCode(FSharpCoreUnreferencedCodeMessage)] + [RequiresDynamicCode(FSharpCoreUnreferencedCodeMessage)] public static bool IsFSharpType(Type type) { if (s_singletonInstance is null) @@ -92,6 +93,7 @@ public static FSharpCoreReflectionProxy Instance } [RequiresUnreferencedCode(FSharpCoreUnreferencedCodeMessage)] + [RequiresDynamicCode(FSharpCoreUnreferencedCodeMessage)] private FSharpCoreReflectionProxy(Assembly fsharpCoreAssembly) { Debug.Assert(fsharpCoreAssembly.GetName().Name == "FSharp.Core"); @@ -112,6 +114,7 @@ private FSharpCoreReflectionProxy(Assembly fsharpCoreAssembly) } [RequiresUnreferencedCode(FSharpCoreUnreferencedCodeMessage)] + [RequiresDynamicCode(FSharpCoreUnreferencedCodeMessage)] public FSharpKind DetectFSharpKind(Type type) { Attribute? compilationMappingAttribute = GetFSharpCompilationMappingAttribute(type); @@ -140,6 +143,7 @@ public FSharpKind DetectFSharpKind(Type type) } [RequiresUnreferencedCode(FSharpCoreUnreferencedCodeMessage)] + [RequiresDynamicCode(FSharpCoreUnreferencedCodeMessage)] public Func CreateFSharpOptionValueGetter<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)] TFSharpOption, T>() { Debug.Assert(typeof(TFSharpOption).GetGenericTypeDefinition() == _fsharpOptionType); @@ -148,6 +152,7 @@ public FSharpKind DetectFSharpKind(Type type) } [RequiresUnreferencedCode(FSharpCoreUnreferencedCodeMessage)] + [RequiresDynamicCode(FSharpCoreUnreferencedCodeMessage)] public Func CreateFSharpOptionSomeConstructor<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)] TFSharpOption, TElement>() { Debug.Assert(typeof(TFSharpOption).GetGenericTypeDefinition() == _fsharpOptionType); @@ -156,6 +161,7 @@ public FSharpKind DetectFSharpKind(Type type) } [RequiresUnreferencedCode(FSharpCoreUnreferencedCodeMessage)] + [RequiresDynamicCode(FSharpCoreUnreferencedCodeMessage)] public StructGetter CreateFSharpValueOptionValueGetter<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)] TFSharpValueOption, TElement>() where TFSharpValueOption : struct { @@ -165,6 +171,7 @@ public FSharpKind DetectFSharpKind(Type type) } [RequiresUnreferencedCode(FSharpCoreUnreferencedCodeMessage)] + [RequiresDynamicCode(FSharpCoreUnreferencedCodeMessage)] public Func CreateFSharpValueOptionSomeConstructor<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)] TFSharpOption, TElement>() { Debug.Assert(typeof(TFSharpOption).GetGenericTypeDefinition() == _fsharpValueOptionType); @@ -173,6 +180,7 @@ public FSharpKind DetectFSharpKind(Type type) } [RequiresUnreferencedCode(FSharpCoreUnreferencedCodeMessage)] + [RequiresDynamicCode(FSharpCoreUnreferencedCodeMessage)] public Func, TFSharpList> CreateFSharpListConstructor() { Debug.Assert(typeof(TFSharpList).GetGenericTypeDefinition() == _fsharpListType); @@ -180,6 +188,7 @@ public Func, TFSharpList> CreateFSharpListConstructor, TFSharpSet> CreateFSharpSetConstructor() { Debug.Assert(typeof(TFSharpSet).GetGenericTypeDefinition() == _fsharpSetType); @@ -187,6 +196,7 @@ public Func, TFSharpSet> CreateFSharpSetConstructor>, TFSharpMap> CreateFSharpMapConstructor() { Debug.Assert(typeof(TFSharpMap).GetGenericTypeDefinition() == _fsharpMapType); diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/MemberAccessor.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/MemberAccessor.cs index f01fc5d7493333..7b96897b13499f 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/MemberAccessor.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/MemberAccessor.cs @@ -7,6 +7,7 @@ namespace System.Text.Json.Serialization.Metadata { + [RequiresDynamicCode("Runtime code generation is not available for Aot form factor.")] internal abstract class MemberAccessor { public abstract JsonTypeInfo.ConstructorDelegate? CreateConstructor( diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/ReflectionEmitCachingMemberAccessor.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/ReflectionEmitCachingMemberAccessor.cs index f45bb72f4610a0..e4ecb99e6d1549 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/ReflectionEmitCachingMemberAccessor.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/ReflectionEmitCachingMemberAccessor.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. #if NETFRAMEWORK || NETCOREAPP @@ -8,6 +8,7 @@ namespace System.Text.Json.Serialization.Metadata { + [RequiresDynamicCode("Runtime code generation is not available for Aot form factor.")] internal sealed partial class ReflectionEmitCachingMemberAccessor : MemberAccessor { private static readonly ReflectionEmitMemberAccessor s_sourceAccessor = new(); diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/ReflectionEmitMemberAccessor.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/ReflectionEmitMemberAccessor.cs index 0827931b5df1de..3a4650d6a600ff 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/ReflectionEmitMemberAccessor.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/ReflectionEmitMemberAccessor.cs @@ -10,6 +10,7 @@ namespace System.Text.Json.Serialization.Metadata { + [RequiresDynamicCode("Runtime code generation is not available for Aot form factor.")] internal sealed class ReflectionEmitMemberAccessor : MemberAccessor { public override JsonTypeInfo.ConstructorDelegate? CreateConstructor( @@ -183,6 +184,7 @@ public override Func, TCollection> CreateImmutableEnumerab CreateImmutableEnumerableCreateRangeDelegate(typeof(TCollection), typeof(TElement), typeof(IEnumerable))); [RequiresUnreferencedCode(IEnumerableConverterFactoryHelpers.ImmutableConvertersUnreferencedCodeMessage)] + [RequiresDynamicCode(IEnumerableConverterFactoryHelpers.ImmutableConvertersUnreferencedCodeMessage)] private static DynamicMethod CreateImmutableEnumerableCreateRangeDelegate(Type collectionType, Type elementType, Type enumerableType) { MethodInfo realMethod = collectionType.GetImmutableEnumerableCreateRangeMethod(elementType); @@ -209,6 +211,7 @@ public override Func>, TCollection> Creat CreateImmutableDictionaryCreateRangeDelegate(typeof(TCollection), typeof(TKey), typeof(TValue), typeof(IEnumerable>))); [RequiresUnreferencedCode(IEnumerableConverterFactoryHelpers.ImmutableConvertersUnreferencedCodeMessage)] + [RequiresDynamicCode(IEnumerableConverterFactoryHelpers.ImmutableConvertersUnreferencedCodeMessage)] private static DynamicMethod CreateImmutableDictionaryCreateRangeDelegate(Type collectionType, Type keyType, Type valueType, Type enumerableType) { MethodInfo realMethod = collectionType.GetImmutableDictionaryCreateRangeMethod(keyType, valueType); diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/ReflectionJsonTypeInfoOfT.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/ReflectionJsonTypeInfoOfT.cs index 09ab7932f8ee82..baba3961507bea 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/ReflectionJsonTypeInfoOfT.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/ReflectionJsonTypeInfoOfT.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. using System.Collections.Generic; @@ -16,6 +16,7 @@ namespace System.Text.Json.Serialization.Metadata internal sealed class ReflectionJsonTypeInfo : JsonTypeInfo { [RequiresUnreferencedCode(JsonSerializer.SerializationUnreferencedCodeMessage)] + [RequiresDynamicCode(JsonSerializer.SerializationRequiresDynamicCodeMessage)] internal ReflectionJsonTypeInfo(JsonSerializerOptions options) : this( GetConverter( @@ -28,6 +29,7 @@ internal ReflectionJsonTypeInfo(JsonSerializerOptions options) } [RequiresUnreferencedCode(JsonSerializer.SerializationUnreferencedCodeMessage)] + [RequiresDynamicCode(JsonSerializer.SerializationRequiresDynamicCodeMessage)] internal ReflectionJsonTypeInfo(JsonConverter converter, JsonSerializerOptions options) : base(converter, options) { @@ -43,6 +45,8 @@ internal ReflectionJsonTypeInfo(JsonConverter converter, JsonSerializerOptions o [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "Constructor is marked as RequiresUnreferencedCode")] + [UnconditionalSuppressMessage("AotAnalysis", "IL3050:RequiresDynamicCode", + Justification = "The ctor is marked with RequiresDynamicCode.")] internal override void Configure() { base.Configure(); @@ -50,6 +54,7 @@ internal override void Configure() } [RequiresUnreferencedCode(JsonSerializer.SerializationUnreferencedCodeMessage)] + [RequiresDynamicCode(JsonSerializer.SerializationRequiresDynamicCodeMessage)] private void AddPropertiesAndParametersUsingReflection() { Debug.Assert(PropertyInfoForTypeInfo.ConverterStrategy == ConverterStrategy.Object); diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/ReflectionMemberAccessor.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/ReflectionMemberAccessor.cs index f3d182350838dc..171d66b8ea8172 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/ReflectionMemberAccessor.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/ReflectionMemberAccessor.cs @@ -8,6 +8,7 @@ namespace System.Text.Json.Serialization.Metadata { + [RequiresDynamicCode("Runtime code generation is not available for Aot form factor.")] internal sealed class ReflectionMemberAccessor : MemberAccessor { private sealed class ConstructorContext From 918c860369ff318041f8d183b4880d92ed65a2e4 Mon Sep 17 00:00:00 2001 From: Lakshan Fernando Date: Mon, 25 Apr 2022 16:05:04 -0700 Subject: [PATCH 2/9] FB --- .../System.Text.Json/ref/System.Text.Json.cs | 2 +- .../JsonSerializerOptionsUpdateHandler.cs | 2 +- .../Serialization/JsonStringEnumConverter.cs | 2 +- .../Serialization/Metadata/MemberAccessor.cs | 3 +- .../ReflectionEmitCachingMemberAccessor.cs | 7 +++- .../Metadata/ReflectionEmitMemberAccessor.cs | 32 ++++++++++++++++++- .../Metadata/ReflectionMemberAccessor.cs | 3 +- 7 files changed, 44 insertions(+), 7 deletions(-) diff --git a/src/libraries/System.Text.Json/ref/System.Text.Json.cs b/src/libraries/System.Text.Json/ref/System.Text.Json.cs index 47e48759ab169f..90cab2a6de7ad3 100644 --- a/src/libraries/System.Text.Json/ref/System.Text.Json.cs +++ b/src/libraries/System.Text.Json/ref/System.Text.Json.cs @@ -976,7 +976,7 @@ public partial class JsonStringEnumConverter : System.Text.Json.Serialization.Js public JsonStringEnumConverter() { } public JsonStringEnumConverter(System.Text.Json.JsonNamingPolicy? namingPolicy = null, bool allowIntegerValues = true) { } public sealed override bool CanConvert(System.Type typeToConvert) { throw null; } - [System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Runtime code generation is not available for Aot form factor.")] + [System.Diagnostics.CodeAnalysis.RequiresDynamicCode("JSON serialization and deserialization might require types that might need runtime code generation. Use source generated paths for native aot applications.")] public sealed override System.Text.Json.Serialization.JsonConverter CreateConverter(System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) { throw null; } } public enum JsonUnknownDerivedTypeHandling diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializerOptionsUpdateHandler.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializerOptionsUpdateHandler.cs index 2b037a1a4cba61..d37c61270e9c03 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializerOptionsUpdateHandler.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializerOptionsUpdateHandler.cs @@ -14,7 +14,7 @@ namespace System.Text.Json /// Handler used to clear JsonSerializerOptions reflection cache upon a metadata update. internal static class JsonSerializerOptionsUpdateHandler { - [RequiresDynamicCode("Runtime code generation is not available for Aot form factor.")] + [RequiresDynamicCode("JSON serialization and deserialization might require types that might need runtime code generation. Use source generated paths for native aot applications.")] public static void ClearCache(Type[]? types) { // Ignore the types, and just clear out all reflection caches from serializer options. diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonStringEnumConverter.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonStringEnumConverter.cs index bb05a877151b0f..37a8ce22473a56 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonStringEnumConverter.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonStringEnumConverter.cs @@ -52,7 +52,7 @@ public sealed override bool CanConvert(Type typeToConvert) } /// - [RequiresDynamicCode("Runtime code generation is not available for Aot form factor.")] + [RequiresDynamicCode("JSON serialization and deserialization might require types that might need runtime code generation. Use source generated paths for native aot applications.")] [SuppressMessage("AotAnalysis", "IL3051:'RequiresDynamicCodeAttribute' annotations must match across all interface implementations or overrides.", Justification = "Suppressing base type warnings")] public sealed override JsonConverter CreateConverter(Type typeToConvert, JsonSerializerOptions options) => EnumConverterFactory.Create(typeToConvert, _converterOptions, _namingPolicy, options); diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/MemberAccessor.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/MemberAccessor.cs index 7b96897b13499f..9e3fb51b284980 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/MemberAccessor.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/MemberAccessor.cs @@ -7,7 +7,6 @@ namespace System.Text.Json.Serialization.Metadata { - [RequiresDynamicCode("Runtime code generation is not available for Aot form factor.")] internal abstract class MemberAccessor { public abstract JsonTypeInfo.ConstructorDelegate? CreateConstructor( @@ -21,9 +20,11 @@ public abstract JsonTypeInfo.ParameterizedConstructorDelegate CreateAddMethodDelegate<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)] TCollection>(); [RequiresUnreferencedCode(IEnumerableConverterFactoryHelpers.ImmutableConvertersUnreferencedCodeMessage)] + [RequiresDynamicCode(IEnumerableConverterFactoryHelpers.ImmutableConvertersUnreferencedCodeMessage)] public abstract Func, TCollection> CreateImmutableEnumerableCreateRangeDelegate(); [RequiresUnreferencedCode(IEnumerableConverterFactoryHelpers.ImmutableConvertersUnreferencedCodeMessage)] + [RequiresDynamicCode(IEnumerableConverterFactoryHelpers.ImmutableConvertersUnreferencedCodeMessage)] public abstract Func>, TCollection> CreateImmutableDictionaryCreateRangeDelegate(); public abstract Func CreatePropertyGetter(PropertyInfo propertyInfo); diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/ReflectionEmitCachingMemberAccessor.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/ReflectionEmitCachingMemberAccessor.cs index e4ecb99e6d1549..15d2f416ddb7c7 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/ReflectionEmitCachingMemberAccessor.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/ReflectionEmitCachingMemberAccessor.cs @@ -8,9 +8,12 @@ namespace System.Text.Json.Serialization.Metadata { - [RequiresDynamicCode("Runtime code generation is not available for Aot form factor.")] internal sealed partial class ReflectionEmitCachingMemberAccessor : MemberAccessor { + [RequiresDynamicCode("JSON serialization and deserialization might require types that might need runtime code generation. Use source generated paths for native aot applications.")] + internal ReflectionEmitCachingMemberAccessor() { } + [UnconditionalSuppressMessage("AotAnalysis", "IL3050:RequiresDynamicCode", + Justification = "The ctor is marked with RequiresDynamicCode.")] private static readonly ReflectionEmitMemberAccessor s_sourceAccessor = new(); private static readonly Cache<(string id, Type declaringType, MemberInfo? member)> s_cache = new(slidingExpiration: TimeSpan.FromMilliseconds(1000), evictionInterval: TimeSpan.FromMilliseconds(200)); @@ -36,6 +39,7 @@ public override Action CreateFieldSetter(FieldInfo => s_cache.GetOrAdd((nameof(CreateFieldSetter), typeof(TProperty), fieldInfo), static key => s_sourceAccessor.CreateFieldSetter((FieldInfo)key.member!)); [RequiresUnreferencedCode(IEnumerableConverterFactoryHelpers.ImmutableConvertersUnreferencedCodeMessage)] + [RequiresDynamicCode(IEnumerableConverterFactoryHelpers.ImmutableConvertersUnreferencedCodeMessage)] public override Func>, TCollection> CreateImmutableDictionaryCreateRangeDelegate() => s_cache.GetOrAdd((nameof(CreateImmutableDictionaryCreateRangeDelegate), typeof((TCollection, TKey, TValue)), null), [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", @@ -45,6 +49,7 @@ public override Func>, TCollection> Creat #pragma warning restore IL2026 [RequiresUnreferencedCode(IEnumerableConverterFactoryHelpers.ImmutableConvertersUnreferencedCodeMessage)] + [RequiresDynamicCode(IEnumerableConverterFactoryHelpers.ImmutableConvertersUnreferencedCodeMessage)] public override Func, TCollection> CreateImmutableEnumerableCreateRangeDelegate() => s_cache.GetOrAdd((nameof(CreateImmutableEnumerableCreateRangeDelegate), typeof((TCollection, TElement)), null), [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/ReflectionEmitMemberAccessor.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/ReflectionEmitMemberAccessor.cs index 3a4650d6a600ff..3c085b75e2c736 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/ReflectionEmitMemberAccessor.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/ReflectionEmitMemberAccessor.cs @@ -10,9 +10,14 @@ namespace System.Text.Json.Serialization.Metadata { - [RequiresDynamicCode("Runtime code generation is not available for Aot form factor.")] internal sealed class ReflectionEmitMemberAccessor : MemberAccessor { + + [RequiresDynamicCode("JSON serialization and deserialization might require types that might need runtime code generation. Use source generated paths for native aot applications.")] + internal ReflectionEmitMemberAccessor() { } + + [UnconditionalSuppressMessage("AotAnalysis", "IL3050:RequiresDynamicCode", + Justification = "The ctor is marked with RequiresDynamicCode.")] public override JsonTypeInfo.ConstructorDelegate? CreateConstructor( [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type type) { @@ -62,9 +67,12 @@ internal sealed class ReflectionEmitMemberAccessor : MemberAccessor return (JsonTypeInfo.ConstructorDelegate)dynamicMethod.CreateDelegate(typeof(JsonTypeInfo.ConstructorDelegate)); } + [UnconditionalSuppressMessage("AotAnalysis", "IL3050:RequiresDynamicCode", + Justification = "The ctor is marked with RequiresDynamicCode.")] public override Func? CreateParameterizedConstructor(ConstructorInfo constructor) => CreateDelegate>(CreateParameterizedConstructor(constructor)); + [RequiresDynamicCode("JSON serialization and deserialization might require types that might need runtime code generation. Use source generated paths for native aot applications.")] private static DynamicMethod? CreateParameterizedConstructor(ConstructorInfo constructor) { Type? type = constructor.DeclaringType; @@ -106,11 +114,14 @@ internal sealed class ReflectionEmitMemberAccessor : MemberAccessor return dynamicMethod; } + [UnconditionalSuppressMessage("AotAnalysis", "IL3050:RequiresDynamicCode", + Justification = "The ctor is marked with RequiresDynamicCode.")] public override JsonTypeInfo.ParameterizedConstructorDelegate? CreateParameterizedConstructor(ConstructorInfo constructor) => CreateDelegate>( CreateParameterizedConstructor(constructor, typeof(TArg0), typeof(TArg1), typeof(TArg2), typeof(TArg3))); + [RequiresDynamicCode("JSON serialization and deserialization might require types that might need runtime code generation. Use source generated paths for native aot applications.")] private static DynamicMethod? CreateParameterizedConstructor(ConstructorInfo constructor, Type parameterType1, Type parameterType2, Type parameterType3, Type parameterType4) { Type? type = constructor.DeclaringType; @@ -152,9 +163,12 @@ public override JsonTypeInfo.ParameterizedConstructorDelegate CreateAddMethodDelegate<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)] TCollection>() => CreateDelegate>(CreateAddMethodDelegate(typeof(TCollection))); + [RequiresDynamicCode("JSON serialization and deserialization might require types that might need runtime code generation. Use source generated paths for native aot applications.")] private static DynamicMethod CreateAddMethodDelegate( [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)] Type collectionType) { @@ -179,6 +193,7 @@ private static DynamicMethod CreateAddMethodDelegate( } [RequiresUnreferencedCode(IEnumerableConverterFactoryHelpers.ImmutableConvertersUnreferencedCodeMessage)] + [RequiresDynamicCode(IEnumerableConverterFactoryHelpers.ImmutableConvertersUnreferencedCodeMessage)] public override Func, TCollection> CreateImmutableEnumerableCreateRangeDelegate() => CreateDelegate, TCollection>>( CreateImmutableEnumerableCreateRangeDelegate(typeof(TCollection), typeof(TElement), typeof(IEnumerable))); @@ -206,6 +221,7 @@ private static DynamicMethod CreateImmutableEnumerableCreateRangeDelegate(Type c } [RequiresUnreferencedCode(IEnumerableConverterFactoryHelpers.ImmutableConvertersUnreferencedCodeMessage)] + [RequiresDynamicCode(IEnumerableConverterFactoryHelpers.ImmutableConvertersUnreferencedCodeMessage)] public override Func>, TCollection> CreateImmutableDictionaryCreateRangeDelegate() => CreateDelegate>, TCollection>>( CreateImmutableDictionaryCreateRangeDelegate(typeof(TCollection), typeof(TKey), typeof(TValue), typeof(IEnumerable>))); @@ -232,9 +248,12 @@ private static DynamicMethod CreateImmutableDictionaryCreateRangeDelegate(Type c return dynamicMethod; } + [UnconditionalSuppressMessage("AotAnalysis", "IL3050:RequiresDynamicCode", + Justification = "The ctor is marked with RequiresDynamicCode.")] public override Func CreatePropertyGetter(PropertyInfo propertyInfo) => CreateDelegate>(CreatePropertyGetter(propertyInfo, typeof(TProperty))); + [RequiresDynamicCode("JSON serialization and deserialization might require types that might need runtime code generation. Use source generated paths for native aot applications.")] private static DynamicMethod CreatePropertyGetter(PropertyInfo propertyInfo, Type runtimePropertyType) { MethodInfo? realMethod = propertyInfo.GetMethod; @@ -278,9 +297,12 @@ private static DynamicMethod CreatePropertyGetter(PropertyInfo propertyInfo, Typ return dynamicMethod; } + [UnconditionalSuppressMessage("AotAnalysis", "IL3050:RequiresDynamicCode", + Justification = "The ctor is marked with RequiresDynamicCode.")] public override Action CreatePropertySetter(PropertyInfo propertyInfo) => CreateDelegate>(CreatePropertySetter(propertyInfo, typeof(TProperty))); + [RequiresDynamicCode("JSON serialization and deserialization might require types that might need runtime code generation. Use source generated paths for native aot applications.")] private static DynamicMethod CreatePropertySetter(PropertyInfo propertyInfo, Type runtimePropertyType) { MethodInfo? realMethod = propertyInfo.SetMethod; @@ -316,9 +338,12 @@ private static DynamicMethod CreatePropertySetter(PropertyInfo propertyInfo, Typ return dynamicMethod; } + [UnconditionalSuppressMessage("AotAnalysis", "IL3050:RequiresDynamicCode", + Justification = "The ctor is marked with RequiresDynamicCode.")] public override Func CreateFieldGetter(FieldInfo fieldInfo) => CreateDelegate>(CreateFieldGetter(fieldInfo, typeof(TProperty))); + [RequiresDynamicCode("JSON serialization and deserialization might require types that might need runtime code generation. Use source generated paths for native aot applications.")] private static DynamicMethod CreateFieldGetter(FieldInfo fieldInfo, Type runtimeFieldType) { Type? declaringType = fieldInfo.DeclaringType; @@ -350,9 +375,12 @@ private static DynamicMethod CreateFieldGetter(FieldInfo fieldInfo, Type runtime return dynamicMethod; } + [UnconditionalSuppressMessage("AotAnalysis", "IL3050:RequiresDynamicCode", + Justification = "The ctor is marked with RequiresDynamicCode.")] public override Action CreateFieldSetter(FieldInfo fieldInfo) => CreateDelegate>(CreateFieldSetter(fieldInfo, typeof(TProperty))); + [RequiresDynamicCode("JSON serialization and deserialization might require types that might need runtime code generation. Use source generated paths for native aot applications.")] private static DynamicMethod CreateFieldSetter(FieldInfo fieldInfo, Type runtimeFieldType) { Type? declaringType = fieldInfo.DeclaringType; @@ -381,6 +409,7 @@ private static DynamicMethod CreateFieldSetter(FieldInfo fieldInfo, Type runtime return dynamicMethod; } + [RequiresDynamicCode("JSON serialization and deserialization might require types that might need runtime code generation. Use source generated paths for native aot applications.")] private static DynamicMethod CreateGetterMethod(string memberName, Type memberType) => new DynamicMethod( memberName + "Getter", @@ -389,6 +418,7 @@ private static DynamicMethod CreateGetterMethod(string memberName, Type memberTy typeof(ReflectionEmitMemberAccessor).Module, skipVisibility: true); + [RequiresDynamicCode("JSON serialization and deserialization might require types that might need runtime code generation. Use source generated paths for native aot applications.")] private static DynamicMethod CreateSetterMethod(string memberName, Type memberType) => new DynamicMethod( memberName + "Setter", diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/ReflectionMemberAccessor.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/ReflectionMemberAccessor.cs index 171d66b8ea8172..41527aa309366b 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/ReflectionMemberAccessor.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/ReflectionMemberAccessor.cs @@ -8,7 +8,6 @@ namespace System.Text.Json.Serialization.Metadata { - [RequiresDynamicCode("Runtime code generation is not available for Aot form factor.")] internal sealed class ReflectionMemberAccessor : MemberAccessor { private sealed class ConstructorContext @@ -138,6 +137,7 @@ public override JsonTypeInfo.ParameterizedConstructorDelegate, TCollection> CreateImmutableEnumerableCreateRangeDelegate() { MethodInfo createRange = typeof(TCollection).GetImmutableEnumerableCreateRangeMethod(typeof(TElement)); @@ -146,6 +146,7 @@ public override Func, TCollection> CreateImmutableEnumerab } [RequiresUnreferencedCode(IEnumerableConverterFactoryHelpers.ImmutableConvertersUnreferencedCodeMessage)] + [RequiresDynamicCode(IEnumerableConverterFactoryHelpers.ImmutableConvertersUnreferencedCodeMessage)] public override Func>, TCollection> CreateImmutableDictionaryCreateRangeDelegate() { MethodInfo createRange = typeof(TCollection).GetImmutableDictionaryCreateRangeMethod(typeof(TKey), typeof(TValue)); From d87079cb1be801cbb7e668a93044a1667ec697d4 Mon Sep 17 00:00:00 2001 From: Lakshan Fernando Date: Tue, 26 Apr 2022 05:20:41 -0700 Subject: [PATCH 3/9] FB2 --- .../System.Text.Json/ref/System.Text.Json.cs | 75 ++++++++++--------- .../Text/Json/Nodes/JsonValueNotTrimmable.cs | 4 +- .../IAsyncEnumerableConverterFactory.cs | 2 +- .../Collection/IEnumerableConverterFactory.cs | 2 +- .../FSharp/FSharpTypeConverterFactory.cs | 8 +- .../Object/ObjectConverterFactory.cs | 2 +- .../Serialization/JsonSerializer.Helpers.cs | 2 +- .../JsonSerializerOptions.Converters.cs | 2 +- .../Serialization/JsonSerializerOptions.cs | 2 +- .../JsonSerializerOptionsUpdateHandler.cs | 2 +- .../Serialization/JsonStringEnumConverter.cs | 4 +- .../ReflectionEmitCachingMemberAccessor.cs | 4 +- .../Metadata/ReflectionEmitMemberAccessor.cs | 36 ++++----- .../Metadata/ReflectionJsonTypeInfoOfT.cs | 2 +- 14 files changed, 74 insertions(+), 73 deletions(-) diff --git a/src/libraries/System.Text.Json/ref/System.Text.Json.cs b/src/libraries/System.Text.Json/ref/System.Text.Json.cs index 90cab2a6de7ad3..c273450caed404 100644 --- a/src/libraries/System.Text.Json/ref/System.Text.Json.cs +++ b/src/libraries/System.Text.Json/ref/System.Text.Json.cs @@ -187,142 +187,142 @@ public partial struct JsonReaderState public static partial class JsonSerializer { [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")] - [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use source generated paths for native aot applications.")] + [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("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.")] public static object? Deserialize(System.IO.Stream utf8Json, System.Type returnType, System.Text.Json.JsonSerializerOptions? options = null) { throw null; } public static object? Deserialize(System.IO.Stream utf8Json, System.Type returnType, System.Text.Json.Serialization.JsonSerializerContext context) { throw null; } [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")] - [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use source generated paths for native aot applications.")] + [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("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.")] public static object? Deserialize(System.ReadOnlySpan utf8Json, System.Type returnType, System.Text.Json.JsonSerializerOptions? options = null) { throw null; } public static object? Deserialize(System.ReadOnlySpan utf8Json, System.Type returnType, System.Text.Json.Serialization.JsonSerializerContext context) { throw null; } [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")] - [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use source generated paths for native aot applications.")] + [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("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.")] public static object? Deserialize([System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("Json")] System.ReadOnlySpan json, System.Type returnType, System.Text.Json.JsonSerializerOptions? options = null) { throw null; } public static object? Deserialize([System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("Json")] System.ReadOnlySpan json, System.Type returnType, System.Text.Json.Serialization.JsonSerializerContext context) { throw null; } [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")] - [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use source generated paths for native aot applications.")] + [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("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.")] public static object? Deserialize([System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("Json")] string json, System.Type returnType, System.Text.Json.JsonSerializerOptions? options = null) { throw null; } public static object? Deserialize([System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("Json")] string json, System.Type returnType, System.Text.Json.Serialization.JsonSerializerContext context) { throw null; } [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")] - [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use source generated paths for native aot applications.")] + [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("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.")] public static object? Deserialize(this System.Text.Json.JsonDocument document, System.Type returnType, System.Text.Json.JsonSerializerOptions? options = null) { throw null; } public static object? Deserialize(this System.Text.Json.JsonDocument document, System.Type returnType, System.Text.Json.Serialization.JsonSerializerContext context) { throw null; } [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")] - [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use source generated paths for native aot applications.")] + [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("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.")] public static object? Deserialize(this System.Text.Json.JsonElement element, System.Type returnType, System.Text.Json.JsonSerializerOptions? options = null) { throw null; } public static object? Deserialize(this System.Text.Json.JsonElement element, System.Type returnType, System.Text.Json.Serialization.JsonSerializerContext context) { throw null; } [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")] - [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use source generated paths for native aot applications.")] + [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("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.")] public static object? Deserialize(this System.Text.Json.Nodes.JsonNode? node, System.Type returnType, System.Text.Json.JsonSerializerOptions? options = null) { throw null; } public static object? Deserialize(this System.Text.Json.Nodes.JsonNode? node, System.Type returnType, System.Text.Json.Serialization.JsonSerializerContext context) { throw null; } [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")] - [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use source generated paths for native aot applications.")] + [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("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.")] public static object? Deserialize(ref System.Text.Json.Utf8JsonReader reader, System.Type returnType, System.Text.Json.JsonSerializerOptions? options = null) { throw null; } public static object? Deserialize(ref System.Text.Json.Utf8JsonReader reader, System.Type returnType, System.Text.Json.Serialization.JsonSerializerContext context) { throw null; } [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")] - [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use source generated paths for native aot applications.")] + [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("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.")] public static System.Threading.Tasks.ValueTask DeserializeAsync(System.IO.Stream utf8Json, System.Type returnType, System.Text.Json.JsonSerializerOptions? options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public static System.Threading.Tasks.ValueTask DeserializeAsync(System.IO.Stream utf8Json, System.Type returnType, System.Text.Json.Serialization.JsonSerializerContext context, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")] - [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use source generated paths for native aot applications.")] + [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("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.")] public static System.Collections.Generic.IAsyncEnumerable DeserializeAsyncEnumerable(System.IO.Stream utf8Json, System.Text.Json.JsonSerializerOptions? options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")] - [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use source generated paths for native aot applications.")] + [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("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.")] public static System.Threading.Tasks.ValueTask DeserializeAsync(System.IO.Stream utf8Json, System.Text.Json.JsonSerializerOptions? options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public static System.Threading.Tasks.ValueTask DeserializeAsync(System.IO.Stream utf8Json, System.Text.Json.Serialization.Metadata.JsonTypeInfo jsonTypeInfo, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")] - [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use source generated paths for native aot applications.")] + [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("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.")] public static TValue? Deserialize(System.IO.Stream utf8Json, System.Text.Json.JsonSerializerOptions? options = null) { throw null; } public static TValue? Deserialize(System.IO.Stream utf8Json, System.Text.Json.Serialization.Metadata.JsonTypeInfo jsonTypeInfo) { throw null; } [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")] - [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use source generated paths for native aot applications.")] + [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("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.")] public static TValue? Deserialize(System.ReadOnlySpan utf8Json, System.Text.Json.JsonSerializerOptions? options = null) { throw null; } public static TValue? Deserialize(System.ReadOnlySpan utf8Json, System.Text.Json.Serialization.Metadata.JsonTypeInfo jsonTypeInfo) { throw null; } [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")] - [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use source generated paths for native aot applications.")] + [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("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.")] public static TValue? Deserialize([System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("Json")] System.ReadOnlySpan json, System.Text.Json.JsonSerializerOptions? options = null) { throw null; } public static TValue? Deserialize([System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("Json")] System.ReadOnlySpan json, System.Text.Json.Serialization.Metadata.JsonTypeInfo jsonTypeInfo) { throw null; } [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")] - [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use source generated paths for native aot applications.")] + [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("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.")] public static TValue? Deserialize([System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("Json")] string json, System.Text.Json.JsonSerializerOptions? options = null) { throw null; } public static TValue? Deserialize([System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("Json")] string json, System.Text.Json.Serialization.Metadata.JsonTypeInfo jsonTypeInfo) { throw null; } [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")] - [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use source generated paths for native aot applications.")] + [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("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.")] public static TValue? Deserialize(this System.Text.Json.JsonDocument document, System.Text.Json.JsonSerializerOptions? options = null) { throw null; } public static TValue? Deserialize(this System.Text.Json.JsonDocument document, System.Text.Json.Serialization.Metadata.JsonTypeInfo jsonTypeInfo) { throw null; } [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")] - [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use source generated paths for native aot applications.")] + [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("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.")] public static TValue? Deserialize(this System.Text.Json.JsonElement element, System.Text.Json.JsonSerializerOptions? options = null) { throw null; } public static TValue? Deserialize(this System.Text.Json.JsonElement element, System.Text.Json.Serialization.Metadata.JsonTypeInfo jsonTypeInfo) { throw null; } [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")] - [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use source generated paths for native aot applications.")] + [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("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.")] public static TValue? Deserialize(this System.Text.Json.Nodes.JsonNode? node, System.Text.Json.JsonSerializerOptions? options = null) { throw null; } public static TValue? Deserialize(this System.Text.Json.Nodes.JsonNode? node, System.Text.Json.Serialization.Metadata.JsonTypeInfo jsonTypeInfo) { throw null; } [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")] - [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use source generated paths for native aot applications.")] + [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("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.")] public static TValue? Deserialize(ref System.Text.Json.Utf8JsonReader reader, System.Text.Json.JsonSerializerOptions? options = null) { throw null; } public static TValue? Deserialize(ref System.Text.Json.Utf8JsonReader reader, System.Text.Json.Serialization.Metadata.JsonTypeInfo jsonTypeInfo) { throw null; } [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")] - [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use source generated paths for native aot applications.")] + [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("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.")] public static void Serialize(System.IO.Stream utf8Json, object? value, System.Type inputType, System.Text.Json.JsonSerializerOptions? options = null) { } public static void Serialize(System.IO.Stream utf8Json, object? value, System.Type inputType, System.Text.Json.Serialization.JsonSerializerContext context) { } [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")] - [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use source generated paths for native aot applications.")] + [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("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.")] public static string Serialize(object? value, System.Type inputType, System.Text.Json.JsonSerializerOptions? options = null) { throw null; } public static string Serialize(object? value, System.Type inputType, System.Text.Json.Serialization.JsonSerializerContext context) { throw null; } [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")] - [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use source generated paths for native aot applications.")] + [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("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.")] public static void Serialize(System.Text.Json.Utf8JsonWriter writer, object? value, System.Type inputType, System.Text.Json.JsonSerializerOptions? options = null) { } public static void Serialize(System.Text.Json.Utf8JsonWriter writer, object? value, System.Type inputType, System.Text.Json.Serialization.JsonSerializerContext context) { } [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")] - [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use source generated paths for native aot applications.")] + [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("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.")] public static System.Threading.Tasks.Task SerializeAsync(System.IO.Stream utf8Json, object? value, System.Type inputType, System.Text.Json.JsonSerializerOptions? options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public static System.Threading.Tasks.Task SerializeAsync(System.IO.Stream utf8Json, object? value, System.Type inputType, System.Text.Json.Serialization.JsonSerializerContext context, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")] - [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use source generated paths for native aot applications.")] + [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("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.")] public static System.Threading.Tasks.Task SerializeAsync(System.IO.Stream utf8Json, TValue value, System.Text.Json.JsonSerializerOptions? options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public static System.Threading.Tasks.Task SerializeAsync(System.IO.Stream utf8Json, TValue value, System.Text.Json.Serialization.Metadata.JsonTypeInfo jsonTypeInfo, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")] - [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use source generated paths for native aot applications.")] + [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("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.")] public static System.Text.Json.JsonDocument SerializeToDocument(object? value, System.Type inputType, System.Text.Json.JsonSerializerOptions? options = null) { throw null; } public static System.Text.Json.JsonDocument SerializeToDocument(object? value, System.Type inputType, System.Text.Json.Serialization.JsonSerializerContext context) { throw null; } [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")] - [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use source generated paths for native aot applications.")] + [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("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.")] public static System.Text.Json.JsonDocument SerializeToDocument(TValue value, System.Text.Json.JsonSerializerOptions? options = null) { throw null; } public static System.Text.Json.JsonDocument SerializeToDocument(TValue value, System.Text.Json.Serialization.Metadata.JsonTypeInfo jsonTypeInfo) { throw null; } [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")] - [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use source generated paths for native aot applications.")] + [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("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.")] public static System.Text.Json.JsonElement SerializeToElement(object? value, System.Type inputType, System.Text.Json.JsonSerializerOptions? options = null) { throw null; } public static System.Text.Json.JsonElement SerializeToElement(object? value, System.Type inputType, System.Text.Json.Serialization.JsonSerializerContext context) { throw null; } [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")] - [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use source generated paths for native aot applications.")] + [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("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.")] public static System.Text.Json.JsonElement SerializeToElement(TValue value, System.Text.Json.JsonSerializerOptions? options = null) { throw null; } public static System.Text.Json.JsonElement SerializeToElement(TValue value, System.Text.Json.Serialization.Metadata.JsonTypeInfo jsonTypeInfo) { throw null; } [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")] - [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use source generated paths for native aot applications.")] + [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("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.")] public static System.Text.Json.Nodes.JsonNode? SerializeToNode(object? value, System.Type inputType, System.Text.Json.JsonSerializerOptions? options = null) { throw null; } public static System.Text.Json.Nodes.JsonNode? SerializeToNode(object? value, System.Type inputType, System.Text.Json.Serialization.JsonSerializerContext context) { throw null; } [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")] - [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use source generated paths for native aot applications.")] + [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("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.")] public static System.Text.Json.Nodes.JsonNode? SerializeToNode(TValue value, System.Text.Json.JsonSerializerOptions? options = null) { throw null; } public static System.Text.Json.Nodes.JsonNode? SerializeToNode(TValue value, System.Text.Json.Serialization.Metadata.JsonTypeInfo jsonTypeInfo) { throw null; } [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")] - [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use source generated paths for native aot applications.")] + [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("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.")] public static byte[] SerializeToUtf8Bytes(object? value, System.Type inputType, System.Text.Json.JsonSerializerOptions? options = null) { throw null; } public static byte[] SerializeToUtf8Bytes(object? value, System.Type inputType, System.Text.Json.Serialization.JsonSerializerContext context) { throw null; } [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")] - [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use source generated paths for native aot applications.")] + [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("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.")] public static byte[] SerializeToUtf8Bytes(TValue value, System.Text.Json.JsonSerializerOptions? options = null) { throw null; } public static byte[] SerializeToUtf8Bytes(TValue value, System.Text.Json.Serialization.Metadata.JsonTypeInfo jsonTypeInfo) { throw null; } [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")] - [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use source generated paths for native aot applications.")] + [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("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.")] public static void Serialize(System.IO.Stream utf8Json, TValue value, System.Text.Json.JsonSerializerOptions? options = null) { } public static void Serialize(System.IO.Stream utf8Json, TValue value, System.Text.Json.Serialization.Metadata.JsonTypeInfo jsonTypeInfo) { } [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")] - [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use source generated paths for native aot applications.")] + [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("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.")] public static void Serialize(System.Text.Json.Utf8JsonWriter writer, TValue value, System.Text.Json.JsonSerializerOptions? options = null) { } public static void Serialize(System.Text.Json.Utf8JsonWriter writer, TValue value, System.Text.Json.Serialization.Metadata.JsonTypeInfo jsonTypeInfo) { } [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")] - [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use source generated paths for native aot applications.")] + [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("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.")] public static string Serialize(TValue value, System.Text.Json.JsonSerializerOptions? options = null) { throw null; } public static string Serialize(TValue value, System.Text.Json.Serialization.Metadata.JsonTypeInfo jsonTypeInfo) { throw null; } } @@ -360,7 +360,7 @@ public JsonSerializerOptions(System.Text.Json.JsonSerializerOptions options) { } public bool WriteIndented { get { throw null; } set { } } public void AddContext() where TContext : System.Text.Json.Serialization.JsonSerializerContext, new() { } [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Getting a converter for a type may require reflection which depends on unreferenced code.")] - [System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Getting a converter for a type may require reflection which depends on unreferenced code.")] + [System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Getting a converter for a type may require reflection which depends on dynamic code.")] public System.Text.Json.Serialization.JsonConverter GetConverter(System.Type typeToConvert) { throw null; } } public enum JsonTokenType : byte @@ -973,10 +973,11 @@ public enum JsonSourceGenerationMode } public partial class JsonStringEnumConverter : System.Text.Json.Serialization.JsonConverterFactory { + [System.Diagnostics.CodeAnalysis.RequiresDynamicCode("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.")] public JsonStringEnumConverter() { } + [System.Diagnostics.CodeAnalysis.RequiresDynamicCode("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.")] public JsonStringEnumConverter(System.Text.Json.JsonNamingPolicy? namingPolicy = null, bool allowIntegerValues = true) { } public sealed override bool CanConvert(System.Type typeToConvert) { throw null; } - [System.Diagnostics.CodeAnalysis.RequiresDynamicCode("JSON serialization and deserialization might require types that might need runtime code generation. Use source generated paths for native aot applications.")] public sealed override System.Text.Json.Serialization.JsonConverter CreateConverter(System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) { throw null; } } public enum JsonUnknownDerivedTypeHandling diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Nodes/JsonValueNotTrimmable.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Nodes/JsonValueNotTrimmable.cs index 056fccbb3379f7..c5bdd0154adc4c 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Nodes/JsonValueNotTrimmable.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Nodes/JsonValueNotTrimmable.cs @@ -15,9 +15,9 @@ internal sealed partial class JsonValueNotTrimmable : JsonValue public JsonValueNotTrimmable(TValue value, JsonNodeOptions? options = null) : base(value, options) { } [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", - Justification = "The ctor is marked with RequiresUnreferencedCode.")] + Justification = "The ctor is marked RequiresUnreferencedCode.")] [UnconditionalSuppressMessage("AotAnalysis", "IL3050:RequiresDynamicCode", - Justification = "The ctor is marked with RequiresDynamicCode.")] + Justification = "The ctor is marked RequiresDynamicCode.")] public override void WriteTo(Utf8JsonWriter writer, JsonSerializerOptions? options = null) { if (writer is null) diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/IAsyncEnumerableConverterFactory.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/IAsyncEnumerableConverterFactory.cs index 6bf1a1a9f2459f..c657cd453502b4 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/IAsyncEnumerableConverterFactory.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/IAsyncEnumerableConverterFactory.cs @@ -23,7 +23,7 @@ public IAsyncEnumerableConverterFactory() { } [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "The ctor is marked RequiresUnreferencedCode.")] [UnconditionalSuppressMessage("AotAnalysis", "IL3050:RequiresDynamicCode", - Justification = "The ctor is marked with RequiresDynamicCode.")] + Justification = "The ctor is marked RequiresDynamicCode.")] public override JsonConverter CreateConverter(Type typeToConvert, JsonSerializerOptions options) { Type? asyncEnumerableInterface = GetAsyncEnumerableInterface(typeToConvert); diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/IEnumerableConverterFactory.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/IEnumerableConverterFactory.cs index 462f918c906be1..bd11ad1a5630a9 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/IEnumerableConverterFactory.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/IEnumerableConverterFactory.cs @@ -32,7 +32,7 @@ public override bool CanConvert(Type typeToConvert) [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "The ctor is marked RequiresUnreferencedCode.")] [UnconditionalSuppressMessage("AotAnalysis", "IL3050:RequiresDynamicCode", - Justification = "The ctor is marked with RequiresDynamicCode.")] + Justification = "The ctor is marked RequiresDynamicCode.")] public override JsonConverter CreateConverter(Type typeToConvert, JsonSerializerOptions options) { Type converterType; diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/FSharp/FSharpTypeConverterFactory.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/FSharp/FSharpTypeConverterFactory.cs index ef130d1f9fe448..75d7845cfff5b0 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/FSharp/FSharpTypeConverterFactory.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/FSharp/FSharpTypeConverterFactory.cs @@ -17,17 +17,17 @@ public FSharpTypeConverterFactory() { } private ObjectConverterFactory? _recordConverterFactory; [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", - Justification = "The ctor is marked with RequiresUnreferencedCode.")] + Justification = "The ctor is marked RequiresUnreferencedCode.")] [UnconditionalSuppressMessage("AotAnalysis", "IL3050:RequiresDynamicCode", - Justification = "The ctor is marked with RequiresDynamicCode.")] + Justification = "The ctor is marked RequiresDynamicCode.")] public override bool CanConvert(Type typeToConvert) => FSharpCoreReflectionProxy.IsFSharpType(typeToConvert) && FSharpCoreReflectionProxy.Instance.DetectFSharpKind(typeToConvert) is not FSharpKind.Unrecognized; [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", - Justification = "The ctor is marked with RequiresUnreferencedCode.")] + Justification = "The ctor is marked RequiresUnreferencedCode.")] [UnconditionalSuppressMessage("AotAnalysis", "IL3050:RequiresDynamicCode", - Justification = "The ctor is marked with RequiresDynamicCode.")] + Justification = "The ctor is marked RequiresDynamicCode.")] public override JsonConverter? CreateConverter(Type typeToConvert, JsonSerializerOptions options) { Debug.Assert(CanConvert(typeToConvert)); diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Object/ObjectConverterFactory.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Object/ObjectConverterFactory.cs index 22bf7962296fad..e288b2f4dfc0fe 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Object/ObjectConverterFactory.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Object/ObjectConverterFactory.cs @@ -38,7 +38,7 @@ public override bool CanConvert(Type typeToConvert) [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2067:UnrecognizedReflectionPattern", Justification = "The ctor is marked RequiresUnreferencedCode.")] [UnconditionalSuppressMessage("AotAnalysis", "IL3050:RequiresDynamicCode", - Justification = "The ctor is marked with RequiresDynamicCode.")] + Justification = "The ctor is marked RequiresDynamicCode.")] public override JsonConverter CreateConverter(Type typeToConvert, JsonSerializerOptions options) { if (typeToConvert.IsKeyValuePair()) diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Helpers.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Helpers.cs index de4c61f0614c36..7e56f52f29ab99 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Helpers.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Helpers.cs @@ -11,7 +11,7 @@ namespace System.Text.Json public static partial class JsonSerializer { internal const string SerializationUnreferencedCodeMessage = "JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved."; - internal const string SerializationRequiresDynamicCodeMessage = "JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use source generated paths for native aot applications."; + internal const string SerializationRequiresDynamicCodeMessage = "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."; [RequiresUnreferencedCode(SerializationUnreferencedCodeMessage)] [RequiresDynamicCode(SerializationRequiresDynamicCodeMessage)] diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializerOptions.Converters.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializerOptions.Converters.cs index 8de6c2f73f7356..7ec6e9cfd1cb5a 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializerOptions.Converters.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializerOptions.Converters.cs @@ -216,7 +216,7 @@ internal JsonConverter GetConverterFromMember(Type? parentClassType, Type proper /// for or its serializable members. /// [RequiresUnreferencedCode("Getting a converter for a type may require reflection which depends on unreferenced code.")] - [RequiresDynamicCode("Getting a converter for a type may require reflection which depends on unreferenced code.")] + [RequiresDynamicCode("Getting a converter for a type may require reflection which depends on dynamic code.")] public JsonConverter GetConverter(Type typeToConvert) { if (typeToConvert is null) diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializerOptions.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializerOptions.cs index 3a73a328952cc9..5a75dfea82aecd 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializerOptions.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializerOptions.cs @@ -571,7 +571,7 @@ internal JsonSerializerContext? JsonSerializerContext // The cached value used to determine if ReferenceHandler should use Preserve or IgnoreCycles semanitcs or None of them. internal ReferenceHandlingStrategy ReferenceHandlingStrategy = ReferenceHandlingStrategy.None; - [UnconditionalSuppressMessage("AotAnalysis", "IL3050:RequiresDynamicCode", Justification = "Dyanmic path is guarded by the the runtime feature switch.")] + [UnconditionalSuppressMessage("AotAnalysis", "IL3050:RequiresDynamicCode", Justification = "Dyanmic path is guarded by the runtime feature switch.")] internal MemberAccessor MemberAccessorStrategy { get diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializerOptionsUpdateHandler.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializerOptionsUpdateHandler.cs index d37c61270e9c03..1fb8177f76019c 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializerOptionsUpdateHandler.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializerOptionsUpdateHandler.cs @@ -14,7 +14,7 @@ namespace System.Text.Json /// Handler used to clear JsonSerializerOptions reflection cache upon a metadata update. internal static class JsonSerializerOptionsUpdateHandler { - [RequiresDynamicCode("JSON serialization and deserialization might require types that might need runtime code generation. Use source generated paths for native aot applications.")] + [RequiresDynamicCode("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.")] public static void ClearCache(Type[]? types) { // Ignore the types, and just clear out all reflection caches from serializer options. diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonStringEnumConverter.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonStringEnumConverter.cs index 37a8ce22473a56..3bbe28a0917e4f 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonStringEnumConverter.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonStringEnumConverter.cs @@ -21,6 +21,7 @@ public class JsonStringEnumConverter : JsonConverterFactory /// Constructor. Creates the with the /// default naming policy and allows integer values. /// + [RequiresDynamicCode("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.")] public JsonStringEnumConverter() : this(namingPolicy: null, allowIntegerValues: true) { @@ -37,6 +38,7 @@ public JsonStringEnumConverter() /// True to allow undefined enum values. When true, if an enum value isn't /// defined it will output as a number rather than a string. /// + [RequiresDynamicCode("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.")] public JsonStringEnumConverter(JsonNamingPolicy? namingPolicy = null, bool allowIntegerValues = true) { _namingPolicy = namingPolicy; @@ -52,8 +54,6 @@ public sealed override bool CanConvert(Type typeToConvert) } /// - [RequiresDynamicCode("JSON serialization and deserialization might require types that might need runtime code generation. Use source generated paths for native aot applications.")] - [SuppressMessage("AotAnalysis", "IL3051:'RequiresDynamicCodeAttribute' annotations must match across all interface implementations or overrides.", Justification = "Suppressing base type warnings")] public sealed override JsonConverter CreateConverter(Type typeToConvert, JsonSerializerOptions options) => EnumConverterFactory.Create(typeToConvert, _converterOptions, _namingPolicy, options); } diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/ReflectionEmitCachingMemberAccessor.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/ReflectionEmitCachingMemberAccessor.cs index 15d2f416ddb7c7..a57f1dc5d976ff 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/ReflectionEmitCachingMemberAccessor.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/ReflectionEmitCachingMemberAccessor.cs @@ -10,10 +10,10 @@ namespace System.Text.Json.Serialization.Metadata { internal sealed partial class ReflectionEmitCachingMemberAccessor : MemberAccessor { - [RequiresDynamicCode("JSON serialization and deserialization might require types that might need runtime code generation. Use source generated paths for native aot applications.")] + [RequiresDynamicCode("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.")] internal ReflectionEmitCachingMemberAccessor() { } [UnconditionalSuppressMessage("AotAnalysis", "IL3050:RequiresDynamicCode", - Justification = "The ctor is marked with RequiresDynamicCode.")] + Justification = "The ctor is marked RequiresDynamicCode.")] private static readonly ReflectionEmitMemberAccessor s_sourceAccessor = new(); private static readonly Cache<(string id, Type declaringType, MemberInfo? member)> s_cache = new(slidingExpiration: TimeSpan.FromMilliseconds(1000), evictionInterval: TimeSpan.FromMilliseconds(200)); diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/ReflectionEmitMemberAccessor.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/ReflectionEmitMemberAccessor.cs index 3c085b75e2c736..df54cc0ce3796b 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/ReflectionEmitMemberAccessor.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/ReflectionEmitMemberAccessor.cs @@ -13,11 +13,11 @@ namespace System.Text.Json.Serialization.Metadata internal sealed class ReflectionEmitMemberAccessor : MemberAccessor { - [RequiresDynamicCode("JSON serialization and deserialization might require types that might need runtime code generation. Use source generated paths for native aot applications.")] + [RequiresDynamicCode("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.")] internal ReflectionEmitMemberAccessor() { } [UnconditionalSuppressMessage("AotAnalysis", "IL3050:RequiresDynamicCode", - Justification = "The ctor is marked with RequiresDynamicCode.")] + Justification = "The ctor is marked RequiresDynamicCode.")] public override JsonTypeInfo.ConstructorDelegate? CreateConstructor( [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type type) { @@ -68,11 +68,11 @@ internal ReflectionEmitMemberAccessor() { } } [UnconditionalSuppressMessage("AotAnalysis", "IL3050:RequiresDynamicCode", - Justification = "The ctor is marked with RequiresDynamicCode.")] + Justification = "The ctor is marked RequiresDynamicCode.")] public override Func? CreateParameterizedConstructor(ConstructorInfo constructor) => CreateDelegate>(CreateParameterizedConstructor(constructor)); - [RequiresDynamicCode("JSON serialization and deserialization might require types that might need runtime code generation. Use source generated paths for native aot applications.")] + [RequiresDynamicCode("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.")] private static DynamicMethod? CreateParameterizedConstructor(ConstructorInfo constructor) { Type? type = constructor.DeclaringType; @@ -115,13 +115,13 @@ internal ReflectionEmitMemberAccessor() { } } [UnconditionalSuppressMessage("AotAnalysis", "IL3050:RequiresDynamicCode", - Justification = "The ctor is marked with RequiresDynamicCode.")] + Justification = "The ctor is marked RequiresDynamicCode.")] public override JsonTypeInfo.ParameterizedConstructorDelegate? CreateParameterizedConstructor(ConstructorInfo constructor) => CreateDelegate>( CreateParameterizedConstructor(constructor, typeof(TArg0), typeof(TArg1), typeof(TArg2), typeof(TArg3))); - [RequiresDynamicCode("JSON serialization and deserialization might require types that might need runtime code generation. Use source generated paths for native aot applications.")] + [RequiresDynamicCode("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.")] private static DynamicMethod? CreateParameterizedConstructor(ConstructorInfo constructor, Type parameterType1, Type parameterType2, Type parameterType3, Type parameterType4) { Type? type = constructor.DeclaringType; @@ -164,11 +164,11 @@ public override JsonTypeInfo.ParameterizedConstructorDelegate CreateAddMethodDelegate<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)] TCollection>() => CreateDelegate>(CreateAddMethodDelegate(typeof(TCollection))); - [RequiresDynamicCode("JSON serialization and deserialization might require types that might need runtime code generation. Use source generated paths for native aot applications.")] + [RequiresDynamicCode("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.")] private static DynamicMethod CreateAddMethodDelegate( [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)] Type collectionType) { @@ -249,11 +249,11 @@ private static DynamicMethod CreateImmutableDictionaryCreateRangeDelegate(Type c } [UnconditionalSuppressMessage("AotAnalysis", "IL3050:RequiresDynamicCode", - Justification = "The ctor is marked with RequiresDynamicCode.")] + Justification = "The ctor is marked RequiresDynamicCode.")] public override Func CreatePropertyGetter(PropertyInfo propertyInfo) => CreateDelegate>(CreatePropertyGetter(propertyInfo, typeof(TProperty))); - [RequiresDynamicCode("JSON serialization and deserialization might require types that might need runtime code generation. Use source generated paths for native aot applications.")] + [RequiresDynamicCode("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.")] private static DynamicMethod CreatePropertyGetter(PropertyInfo propertyInfo, Type runtimePropertyType) { MethodInfo? realMethod = propertyInfo.GetMethod; @@ -298,11 +298,11 @@ private static DynamicMethod CreatePropertyGetter(PropertyInfo propertyInfo, Typ } [UnconditionalSuppressMessage("AotAnalysis", "IL3050:RequiresDynamicCode", - Justification = "The ctor is marked with RequiresDynamicCode.")] + Justification = "The ctor is marked RequiresDynamicCode.")] public override Action CreatePropertySetter(PropertyInfo propertyInfo) => CreateDelegate>(CreatePropertySetter(propertyInfo, typeof(TProperty))); - [RequiresDynamicCode("JSON serialization and deserialization might require types that might need runtime code generation. Use source generated paths for native aot applications.")] + [RequiresDynamicCode("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.")] private static DynamicMethod CreatePropertySetter(PropertyInfo propertyInfo, Type runtimePropertyType) { MethodInfo? realMethod = propertyInfo.SetMethod; @@ -339,11 +339,11 @@ private static DynamicMethod CreatePropertySetter(PropertyInfo propertyInfo, Typ } [UnconditionalSuppressMessage("AotAnalysis", "IL3050:RequiresDynamicCode", - Justification = "The ctor is marked with RequiresDynamicCode.")] + Justification = "The ctor is marked RequiresDynamicCode.")] public override Func CreateFieldGetter(FieldInfo fieldInfo) => CreateDelegate>(CreateFieldGetter(fieldInfo, typeof(TProperty))); - [RequiresDynamicCode("JSON serialization and deserialization might require types that might need runtime code generation. Use source generated paths for native aot applications.")] + [RequiresDynamicCode("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.")] private static DynamicMethod CreateFieldGetter(FieldInfo fieldInfo, Type runtimeFieldType) { Type? declaringType = fieldInfo.DeclaringType; @@ -376,11 +376,11 @@ private static DynamicMethod CreateFieldGetter(FieldInfo fieldInfo, Type runtime } [UnconditionalSuppressMessage("AotAnalysis", "IL3050:RequiresDynamicCode", - Justification = "The ctor is marked with RequiresDynamicCode.")] + Justification = "The ctor is marked RequiresDynamicCode.")] public override Action CreateFieldSetter(FieldInfo fieldInfo) => CreateDelegate>(CreateFieldSetter(fieldInfo, typeof(TProperty))); - [RequiresDynamicCode("JSON serialization and deserialization might require types that might need runtime code generation. Use source generated paths for native aot applications.")] + [RequiresDynamicCode("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.")] private static DynamicMethod CreateFieldSetter(FieldInfo fieldInfo, Type runtimeFieldType) { Type? declaringType = fieldInfo.DeclaringType; @@ -409,7 +409,7 @@ private static DynamicMethod CreateFieldSetter(FieldInfo fieldInfo, Type runtime return dynamicMethod; } - [RequiresDynamicCode("JSON serialization and deserialization might require types that might need runtime code generation. Use source generated paths for native aot applications.")] + [RequiresDynamicCode("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.")] private static DynamicMethod CreateGetterMethod(string memberName, Type memberType) => new DynamicMethod( memberName + "Getter", @@ -418,7 +418,7 @@ private static DynamicMethod CreateGetterMethod(string memberName, Type memberTy typeof(ReflectionEmitMemberAccessor).Module, skipVisibility: true); - [RequiresDynamicCode("JSON serialization and deserialization might require types that might need runtime code generation. Use source generated paths for native aot applications.")] + [RequiresDynamicCode("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.")] private static DynamicMethod CreateSetterMethod(string memberName, Type memberType) => new DynamicMethod( memberName + "Setter", diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/ReflectionJsonTypeInfoOfT.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/ReflectionJsonTypeInfoOfT.cs index baba3961507bea..fcc5a2992df16a 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/ReflectionJsonTypeInfoOfT.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/ReflectionJsonTypeInfoOfT.cs @@ -46,7 +46,7 @@ internal ReflectionJsonTypeInfo(JsonConverter converter, JsonSerializerOptions o [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "Constructor is marked as RequiresUnreferencedCode")] [UnconditionalSuppressMessage("AotAnalysis", "IL3050:RequiresDynamicCode", - Justification = "The ctor is marked with RequiresDynamicCode.")] + Justification = "The ctor is marked RequiresDynamicCode.")] internal override void Configure() { base.Configure(); From 865d3a6d4d966c6cd6edd7343604e1a291046fad Mon Sep 17 00:00:00 2001 From: Lakshan Fernando Date: Tue, 26 Apr 2022 13:16:12 -0700 Subject: [PATCH 4/9] FB3 --- src/libraries/System.Text.Json/ref/System.Text.Json.cs | 4 ++-- .../src/System/Text/Json/Nodes/JsonArray.cs | 2 +- .../src/System/Text/Json/Nodes/JsonValue.cs | 3 ++- .../Serialization/Converters/Value/EnumConverterFactory.cs | 3 ++- .../Converters/Value/NullableConverterFactory.cs | 7 ++++++- .../Converters/Value/UnsupportedTypeConverterFactory.cs | 7 ++++++- .../Text/Json/Serialization/JsonSerializerOptions.cs | 1 + 7 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/libraries/System.Text.Json/ref/System.Text.Json.cs b/src/libraries/System.Text.Json/ref/System.Text.Json.cs index c273450caed404..4cee8560f946ae 100644 --- a/src/libraries/System.Text.Json/ref/System.Text.Json.cs +++ b/src/libraries/System.Text.Json/ref/System.Text.Json.cs @@ -609,7 +609,7 @@ public JsonArray(params System.Text.Json.Nodes.JsonNode?[] items) { } bool System.Collections.Generic.ICollection.IsReadOnly { get { throw null; } } public void Add(System.Text.Json.Nodes.JsonNode? item) { } [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Creating JsonValue instances with non-primitive types is not compatible with trimming. It can result in non-primitive types being serialized, which may have their members trimmed.")] - [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("Creating JsonValue instances with non-primitive types is not compatible with trimming. It can result in non-primitive types being serialized, which may have their members trimmed.")] + [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("Creating JsonValue instances with non-primitive types is not compatible with runtime code generation. Use System.Text.Json source generation for native AOT applications.")] public void Add(T? value) { } public void Clear() { } public bool Contains(System.Text.Json.Nodes.JsonNode? item) { throw null; } @@ -802,7 +802,7 @@ public abstract partial class JsonValue : System.Text.Json.Nodes.JsonNode public static System.Text.Json.Nodes.JsonValue Create(ulong value, System.Text.Json.Nodes.JsonNodeOptions? options = default(System.Text.Json.Nodes.JsonNodeOptions?)) { throw null; } public static System.Text.Json.Nodes.JsonValue? Create(T? value, System.Text.Json.Serialization.Metadata.JsonTypeInfo jsonTypeInfo, System.Text.Json.Nodes.JsonNodeOptions? options = default(System.Text.Json.Nodes.JsonNodeOptions?)) { throw null; } [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Creating JsonValue instances with non-primitive types is not compatible with trimming. It can result in non-primitive types being serialized, which may have their members trimmed. Use the overload that takes a JsonTypeInfo, or make sure all of the required types are preserved.")] - [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("Creating JsonValue instances with non-primitive types is not compatible with trimming. It can result in non-primitive types being serialized, which may have their members trimmed. Use the overload that takes a JsonTypeInfo, or make sure all of the required types are preserved.")] + [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("Creating JsonValue instances with non-primitive types is not compatible with runtime code generation. Use System.Text.Json source generation for native AOT applications.")] public static System.Text.Json.Nodes.JsonValue? Create(T? value, System.Text.Json.Nodes.JsonNodeOptions? options = default(System.Text.Json.Nodes.JsonNodeOptions?)) { throw null; } public abstract bool TryGetValue([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] out T? value); } diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Nodes/JsonArray.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Nodes/JsonArray.cs index ee3ec2855c3fae..decf879a2f9330 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Nodes/JsonArray.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Nodes/JsonArray.cs @@ -99,7 +99,7 @@ internal JsonArray (JsonElement element, JsonNodeOptions? options = null) : base /// The object to be added to the end of the . /// [RequiresUnreferencedCode(JsonValue.CreateUnreferencedCodeMessage)] - [RequiresDynamicCode(JsonValue.CreateUnreferencedCodeMessage)] + [RequiresDynamicCode(JsonValue.CreateDynamicCodeMessage)] public void Add(T? value) { if (value == null) diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Nodes/JsonValue.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Nodes/JsonValue.cs index fd01f7f2381409..50715c5bb4217b 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Nodes/JsonValue.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Nodes/JsonValue.cs @@ -14,6 +14,7 @@ namespace System.Text.Json.Nodes public abstract partial class JsonValue : JsonNode { internal const string CreateUnreferencedCodeMessage = "Creating JsonValue instances with non-primitive types is not compatible with trimming. It can result in non-primitive types being serialized, which may have their members trimmed."; + internal const string CreateDynamicCodeMessage = "Creating JsonValue instances with non-primitive types is not compatible with runtime code generation. Use System.Text.Json source generation for native AOT applications."; private protected JsonValue(JsonNodeOptions? options = null) : base(options) { } @@ -28,7 +29,7 @@ private protected JsonValue(JsonNodeOptions? options = null) : base(options) { } /// Options to control the behavior. /// The new instance of the class that contains the specified value. [RequiresUnreferencedCode(CreateUnreferencedCodeMessage + " Use the overload that takes a JsonTypeInfo, or make sure all of the required types are preserved.")] - [RequiresDynamicCode(CreateUnreferencedCodeMessage + " Use the overload that takes a JsonTypeInfo, or make sure all of the required types are preserved.")] + [RequiresDynamicCode(CreateDynamicCodeMessage)] public static JsonValue? Create(T? value, JsonNodeOptions? options = null) { if (value == null) diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/EnumConverterFactory.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/EnumConverterFactory.cs index 4cd989677fed6b..0cd09b1f5a6e32 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/EnumConverterFactory.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/EnumConverterFactory.cs @@ -7,6 +7,7 @@ namespace System.Text.Json.Serialization.Converters { internal sealed class EnumConverterFactory : JsonConverterFactory { + [RequiresDynamicCode("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.")] public EnumConverterFactory() { } @@ -30,7 +31,7 @@ internal static JsonConverter Create(Type enumType, EnumConverterOptions convert Justification = "'EnumConverter where T : struct' implies 'T : new()', so the trimmer is warning calling MakeGenericType here because enumType's constructors are not annotated. " + "But EnumConverter doesn't call new T(), so this is safe.")] [UnconditionalSuppressMessage("AotAnalysis", "IL3050:RequiresDynamicCode", Justification = "The factory constructors are only invoked in the context of reflection serialization code paths " + - "and are marked with 'RequiresDynamicCode'")] + "and are marked RequiresDynamicCode")] [return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] private static Type GetEnumConverterType(Type enumType) => typeof(EnumConverter<>).MakeGenericType(enumType); } diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/NullableConverterFactory.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/NullableConverterFactory.cs index 651c981fc0950b..91bae960e28928 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/NullableConverterFactory.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/NullableConverterFactory.cs @@ -10,6 +10,11 @@ namespace System.Text.Json.Serialization.Converters { internal sealed class NullableConverterFactory : JsonConverterFactory { + [RequiresDynamicCode("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.")] + public NullableConverterFactory() + { + } + public override bool CanConvert(Type typeToConvert) { return typeToConvert.IsNullableOfT(); @@ -47,7 +52,7 @@ public static JsonConverter CreateValueConverter(Type valueTypeToConvert, JsonCo Justification = "'NullableConverter where T : struct' implies 'T : new()', so the trimmer is warning calling MakeGenericType here because valueTypeToConvert's constructors are not annotated. " + "But NullableConverter doesn't call new T(), so this is safe.")] [UnconditionalSuppressMessage("AotAnalysis", "IL3050:RequiresDynamicCode", Justification = "The factory constructors are only invoked in the context of reflection serialization code paths " + - "and are marked with 'RequiresDynamicCode'")] + "and are marked RequiresDynamicCode")] [return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] private static Type GetNullableConverterType(Type valueTypeToConvert) => typeof(NullableConverter<>).MakeGenericType(valueTypeToConvert); } diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/UnsupportedTypeConverterFactory.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/UnsupportedTypeConverterFactory.cs index 499555147a21d0..d0b5811aaa1a5a 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/UnsupportedTypeConverterFactory.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/UnsupportedTypeConverterFactory.cs @@ -9,6 +9,11 @@ namespace System.Text.Json.Serialization.Converters { internal sealed class UnsupportedTypeConverterFactory : JsonConverterFactory { + [RequiresDynamicCode("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.")] + public UnsupportedTypeConverterFactory() + { + } + public override bool CanConvert(Type type) { // If a type is added, also add to the SourceGeneration project. @@ -42,7 +47,7 @@ public override bool CanConvert(Type type) } [UnconditionalSuppressMessage("AotAnalysis", "IL3050:RequiresDynamicCode", Justification = "The factory constructors are only invoked in the context of reflection serialization code paths " + - "and are marked with 'RequiresDynamicCode'")] + "and are marked RequiresDynamicCode")] public override JsonConverter CreateConverter(Type type, JsonSerializerOptions options) { JsonConverter converter = (JsonConverter)Activator.CreateInstance( diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializerOptions.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializerOptions.cs index 5a75dfea82aecd..fd1b4ac9469192 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializerOptions.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializerOptions.cs @@ -571,6 +571,7 @@ internal JsonSerializerContext? JsonSerializerContext // The cached value used to determine if ReferenceHandler should use Preserve or IgnoreCycles semanitcs or None of them. internal ReferenceHandlingStrategy ReferenceHandlingStrategy = ReferenceHandlingStrategy.None; + // Workaround https://github.com/dotnet/linker/issues/2715 [UnconditionalSuppressMessage("AotAnalysis", "IL3050:RequiresDynamicCode", Justification = "Dyanmic path is guarded by the runtime feature switch.")] internal MemberAccessor MemberAccessorStrategy { From 2a71a909dcddfbdb086e4ef7daa8682676d6bbc2 Mon Sep 17 00:00:00 2001 From: Lakshan Fernando Date: Wed, 27 Apr 2022 04:28:15 -0700 Subject: [PATCH 5/9] FB4 --- .../Converters/Value/EnumConverterFactory.cs | 2 +- .../Value/NullableConverterFactory.cs | 2 +- .../Value/UnsupportedTypeConverterFactory.cs | 2 +- .../JsonSerializerOptionsUpdateHandler.cs | 2 +- .../Serialization/JsonStringEnumConverter.cs | 4 ++-- .../ReflectionEmitCachingMemberAccessor.cs | 2 +- .../Metadata/ReflectionEmitMemberAccessor.cs | 20 +++++++++---------- .../Metadata/ReflectionJsonTypeInfoOfT.cs | 2 +- 8 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/EnumConverterFactory.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/EnumConverterFactory.cs index 0cd09b1f5a6e32..1aefae88921605 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/EnumConverterFactory.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/EnumConverterFactory.cs @@ -7,7 +7,7 @@ namespace System.Text.Json.Serialization.Converters { internal sealed class EnumConverterFactory : JsonConverterFactory { - [RequiresDynamicCode("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.")] + [RequiresDynamicCode(JsonSerializer.SerializationRequiresDynamicCodeMessage)] public EnumConverterFactory() { } diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/NullableConverterFactory.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/NullableConverterFactory.cs index 91bae960e28928..029a1068663b88 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/NullableConverterFactory.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/NullableConverterFactory.cs @@ -10,7 +10,7 @@ namespace System.Text.Json.Serialization.Converters { internal sealed class NullableConverterFactory : JsonConverterFactory { - [RequiresDynamicCode("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.")] + [RequiresDynamicCode(JsonSerializer.SerializationRequiresDynamicCodeMessage)] public NullableConverterFactory() { } diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/UnsupportedTypeConverterFactory.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/UnsupportedTypeConverterFactory.cs index d0b5811aaa1a5a..e6bd71ea2e8aac 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/UnsupportedTypeConverterFactory.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/UnsupportedTypeConverterFactory.cs @@ -9,7 +9,7 @@ namespace System.Text.Json.Serialization.Converters { internal sealed class UnsupportedTypeConverterFactory : JsonConverterFactory { - [RequiresDynamicCode("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.")] + [RequiresDynamicCode(JsonSerializer.SerializationRequiresDynamicCodeMessage)] public UnsupportedTypeConverterFactory() { } diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializerOptionsUpdateHandler.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializerOptionsUpdateHandler.cs index 1fb8177f76019c..8f7f94140f0c48 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializerOptionsUpdateHandler.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializerOptionsUpdateHandler.cs @@ -14,7 +14,7 @@ namespace System.Text.Json /// Handler used to clear JsonSerializerOptions reflection cache upon a metadata update. internal static class JsonSerializerOptionsUpdateHandler { - [RequiresDynamicCode("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.")] + [RequiresDynamicCode(JsonSerializer.SerializationRequiresDynamicCodeMessage)] public static void ClearCache(Type[]? types) { // Ignore the types, and just clear out all reflection caches from serializer options. diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonStringEnumConverter.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonStringEnumConverter.cs index 3bbe28a0917e4f..d580d1d54cc0ca 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonStringEnumConverter.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonStringEnumConverter.cs @@ -21,7 +21,7 @@ public class JsonStringEnumConverter : JsonConverterFactory /// Constructor. Creates the with the /// default naming policy and allows integer values. /// - [RequiresDynamicCode("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.")] + [RequiresDynamicCode(JsonSerializer.SerializationRequiresDynamicCodeMessage)] public JsonStringEnumConverter() : this(namingPolicy: null, allowIntegerValues: true) { @@ -38,7 +38,7 @@ public JsonStringEnumConverter() /// True to allow undefined enum values. When true, if an enum value isn't /// defined it will output as a number rather than a string. /// - [RequiresDynamicCode("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.")] + [RequiresDynamicCode(JsonSerializer.SerializationRequiresDynamicCodeMessage)] public JsonStringEnumConverter(JsonNamingPolicy? namingPolicy = null, bool allowIntegerValues = true) { _namingPolicy = namingPolicy; diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/ReflectionEmitCachingMemberAccessor.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/ReflectionEmitCachingMemberAccessor.cs index a57f1dc5d976ff..224223b6879e3a 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/ReflectionEmitCachingMemberAccessor.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/ReflectionEmitCachingMemberAccessor.cs @@ -10,7 +10,7 @@ namespace System.Text.Json.Serialization.Metadata { internal sealed partial class ReflectionEmitCachingMemberAccessor : MemberAccessor { - [RequiresDynamicCode("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.")] + [RequiresDynamicCode(JsonSerializer.SerializationRequiresDynamicCodeMessage)] internal ReflectionEmitCachingMemberAccessor() { } [UnconditionalSuppressMessage("AotAnalysis", "IL3050:RequiresDynamicCode", Justification = "The ctor is marked RequiresDynamicCode.")] diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/ReflectionEmitMemberAccessor.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/ReflectionEmitMemberAccessor.cs index df54cc0ce3796b..d2e6978b941931 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/ReflectionEmitMemberAccessor.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/ReflectionEmitMemberAccessor.cs @@ -13,7 +13,7 @@ namespace System.Text.Json.Serialization.Metadata internal sealed class ReflectionEmitMemberAccessor : MemberAccessor { - [RequiresDynamicCode("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.")] + [RequiresDynamicCode(JsonSerializer.SerializationRequiresDynamicCodeMessage)] internal ReflectionEmitMemberAccessor() { } [UnconditionalSuppressMessage("AotAnalysis", "IL3050:RequiresDynamicCode", @@ -72,7 +72,7 @@ internal ReflectionEmitMemberAccessor() { } public override Func? CreateParameterizedConstructor(ConstructorInfo constructor) => CreateDelegate>(CreateParameterizedConstructor(constructor)); - [RequiresDynamicCode("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.")] + [RequiresDynamicCode(JsonSerializer.SerializationRequiresDynamicCodeMessage)] private static DynamicMethod? CreateParameterizedConstructor(ConstructorInfo constructor) { Type? type = constructor.DeclaringType; @@ -121,7 +121,7 @@ public override JsonTypeInfo.ParameterizedConstructorDelegate>( CreateParameterizedConstructor(constructor, typeof(TArg0), typeof(TArg1), typeof(TArg2), typeof(TArg3))); - [RequiresDynamicCode("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.")] + [RequiresDynamicCode(JsonSerializer.SerializationRequiresDynamicCodeMessage)] private static DynamicMethod? CreateParameterizedConstructor(ConstructorInfo constructor, Type parameterType1, Type parameterType2, Type parameterType3, Type parameterType4) { Type? type = constructor.DeclaringType; @@ -168,7 +168,7 @@ public override JsonTypeInfo.ParameterizedConstructorDelegate CreateAddMethodDelegate<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)] TCollection>() => CreateDelegate>(CreateAddMethodDelegate(typeof(TCollection))); - [RequiresDynamicCode("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.")] + [RequiresDynamicCode(JsonSerializer.SerializationRequiresDynamicCodeMessage)] private static DynamicMethod CreateAddMethodDelegate( [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)] Type collectionType) { @@ -253,7 +253,7 @@ private static DynamicMethod CreateImmutableDictionaryCreateRangeDelegate(Type c public override Func CreatePropertyGetter(PropertyInfo propertyInfo) => CreateDelegate>(CreatePropertyGetter(propertyInfo, typeof(TProperty))); - [RequiresDynamicCode("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.")] + [RequiresDynamicCode(JsonSerializer.SerializationRequiresDynamicCodeMessage)] private static DynamicMethod CreatePropertyGetter(PropertyInfo propertyInfo, Type runtimePropertyType) { MethodInfo? realMethod = propertyInfo.GetMethod; @@ -302,7 +302,7 @@ private static DynamicMethod CreatePropertyGetter(PropertyInfo propertyInfo, Typ public override Action CreatePropertySetter(PropertyInfo propertyInfo) => CreateDelegate>(CreatePropertySetter(propertyInfo, typeof(TProperty))); - [RequiresDynamicCode("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.")] + [RequiresDynamicCode(JsonSerializer.SerializationRequiresDynamicCodeMessage)] private static DynamicMethod CreatePropertySetter(PropertyInfo propertyInfo, Type runtimePropertyType) { MethodInfo? realMethod = propertyInfo.SetMethod; @@ -343,7 +343,7 @@ private static DynamicMethod CreatePropertySetter(PropertyInfo propertyInfo, Typ public override Func CreateFieldGetter(FieldInfo fieldInfo) => CreateDelegate>(CreateFieldGetter(fieldInfo, typeof(TProperty))); - [RequiresDynamicCode("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.")] + [RequiresDynamicCode(JsonSerializer.SerializationRequiresDynamicCodeMessage)] private static DynamicMethod CreateFieldGetter(FieldInfo fieldInfo, Type runtimeFieldType) { Type? declaringType = fieldInfo.DeclaringType; @@ -380,7 +380,7 @@ private static DynamicMethod CreateFieldGetter(FieldInfo fieldInfo, Type runtime public override Action CreateFieldSetter(FieldInfo fieldInfo) => CreateDelegate>(CreateFieldSetter(fieldInfo, typeof(TProperty))); - [RequiresDynamicCode("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.")] + [RequiresDynamicCode(JsonSerializer.SerializationRequiresDynamicCodeMessage)] private static DynamicMethod CreateFieldSetter(FieldInfo fieldInfo, Type runtimeFieldType) { Type? declaringType = fieldInfo.DeclaringType; @@ -409,7 +409,7 @@ private static DynamicMethod CreateFieldSetter(FieldInfo fieldInfo, Type runtime return dynamicMethod; } - [RequiresDynamicCode("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.")] + [RequiresDynamicCode(JsonSerializer.SerializationRequiresDynamicCodeMessage)] private static DynamicMethod CreateGetterMethod(string memberName, Type memberType) => new DynamicMethod( memberName + "Getter", @@ -418,7 +418,7 @@ private static DynamicMethod CreateGetterMethod(string memberName, Type memberTy typeof(ReflectionEmitMemberAccessor).Module, skipVisibility: true); - [RequiresDynamicCode("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.")] + [RequiresDynamicCode(JsonSerializer.SerializationRequiresDynamicCodeMessage)] private static DynamicMethod CreateSetterMethod(string memberName, Type memberType) => new DynamicMethod( memberName + "Setter", diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/ReflectionJsonTypeInfoOfT.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/ReflectionJsonTypeInfoOfT.cs index fcc5a2992df16a..43d18ae473c6ae 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/ReflectionJsonTypeInfoOfT.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/ReflectionJsonTypeInfoOfT.cs @@ -44,7 +44,7 @@ internal ReflectionJsonTypeInfo(JsonConverter converter, JsonSerializerOptions o } [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", - Justification = "Constructor is marked as RequiresUnreferencedCode")] + Justification = "The ctor is marked as RequiresUnreferencedCode")] [UnconditionalSuppressMessage("AotAnalysis", "IL3050:RequiresDynamicCode", Justification = "The ctor is marked RequiresDynamicCode.")] internal override void Configure() From b4839f81df44b3cbbf45c2587e299c37b61bb308 Mon Sep 17 00:00:00 2001 From: Lakshan Fernando Date: Thu, 28 Apr 2022 07:55:36 -0700 Subject: [PATCH 6/9] Move annatation to class level where relevant with the fixed analyzer --- .../System.Text.Json/ref/System.Text.Json.cs | 7 ++--- .../src/System.Text.Json.csproj | 2 ++ .../src/System/Text/Json/Nodes/JsonValue.cs | 2 +- .../Text/Json/Nodes/JsonValueNotTrimmable.cs | 4 +-- .../IAsyncEnumerableConverterFactory.cs | 4 +-- .../Collection/IEnumerableConverterFactory.cs | 4 +-- .../FSharp/FSharpTypeConverterFactory.cs | 6 +--- .../Object/ObjectConverterFactory.cs | 5 +--- .../Converters/Value/EnumConverterFactory.cs | 4 +-- .../Value/NullableConverterFactory.cs | 4 +-- .../Value/UnsupportedTypeConverterFactory.cs | 4 +-- .../JsonSerializerOptions.Converters.cs | 2 ++ .../Serialization/JsonStringEnumConverter.cs | 3 +- .../ReflectionEmitCachingMemberAccessor.cs | 6 +--- .../Metadata/ReflectionEmitMemberAccessor.cs | 29 +------------------ 15 files changed, 19 insertions(+), 67 deletions(-) diff --git a/src/libraries/System.Text.Json/ref/System.Text.Json.cs b/src/libraries/System.Text.Json/ref/System.Text.Json.cs index 4cee8560f946ae..592410e3073238 100644 --- a/src/libraries/System.Text.Json/ref/System.Text.Json.cs +++ b/src/libraries/System.Text.Json/ref/System.Text.Json.cs @@ -609,7 +609,7 @@ public JsonArray(params System.Text.Json.Nodes.JsonNode?[] items) { } bool System.Collections.Generic.ICollection.IsReadOnly { get { throw null; } } public void Add(System.Text.Json.Nodes.JsonNode? item) { } [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Creating JsonValue instances with non-primitive types is not compatible with trimming. It can result in non-primitive types being serialized, which may have their members trimmed.")] - [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("Creating JsonValue instances with non-primitive types is not compatible with runtime code generation. Use System.Text.Json source generation for native AOT applications.")] + [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("Creating JsonValue instances with non-primitive types requires dynamically generating code at runtime.")] public void Add(T? value) { } public void Clear() { } public bool Contains(System.Text.Json.Nodes.JsonNode? item) { throw null; } @@ -802,7 +802,7 @@ public abstract partial class JsonValue : System.Text.Json.Nodes.JsonNode public static System.Text.Json.Nodes.JsonValue Create(ulong value, System.Text.Json.Nodes.JsonNodeOptions? options = default(System.Text.Json.Nodes.JsonNodeOptions?)) { throw null; } public static System.Text.Json.Nodes.JsonValue? Create(T? value, System.Text.Json.Serialization.Metadata.JsonTypeInfo jsonTypeInfo, System.Text.Json.Nodes.JsonNodeOptions? options = default(System.Text.Json.Nodes.JsonNodeOptions?)) { throw null; } [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Creating JsonValue instances with non-primitive types is not compatible with trimming. It can result in non-primitive types being serialized, which may have their members trimmed. Use the overload that takes a JsonTypeInfo, or make sure all of the required types are preserved.")] - [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("Creating JsonValue instances with non-primitive types is not compatible with runtime code generation. Use System.Text.Json source generation for native AOT applications.")] + [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("Creating JsonValue instances with non-primitive types requires dynamically generating code at runtime.")] public static System.Text.Json.Nodes.JsonValue? Create(T? value, System.Text.Json.Nodes.JsonNodeOptions? options = default(System.Text.Json.Nodes.JsonNodeOptions?)) { throw null; } public abstract bool TryGetValue([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] out T? value); } @@ -971,11 +971,10 @@ public enum JsonSourceGenerationMode Metadata = 1, Serialization = 2, } + [System.Diagnostics.CodeAnalysis.RequiresDynamicCode("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.")] public partial class JsonStringEnumConverter : System.Text.Json.Serialization.JsonConverterFactory { - [System.Diagnostics.CodeAnalysis.RequiresDynamicCode("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.")] public JsonStringEnumConverter() { } - [System.Diagnostics.CodeAnalysis.RequiresDynamicCode("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.")] public JsonStringEnumConverter(System.Text.Json.JsonNamingPolicy? namingPolicy = null, bool allowIntegerValues = true) { } public sealed override bool CanConvert(System.Type typeToConvert) { throw null; } public sealed override System.Text.Json.Serialization.JsonConverter CreateConverter(System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) { throw null; } diff --git a/src/libraries/System.Text.Json/src/System.Text.Json.csproj b/src/libraries/System.Text.Json/src/System.Text.Json.csproj index 77cff3624a9b88..b3bf13f32cd63b 100644 --- a/src/libraries/System.Text.Json/src/System.Text.Json.csproj +++ b/src/libraries/System.Text.Json/src/System.Text.Json.csproj @@ -8,6 +8,8 @@ CS8969 true true + + true Provides high-performance and low-allocating types that serialize objects to JavaScript Object Notation (JSON) text and deserialize JSON text to objects, with UTF-8 support built-in. Also provides types to read and write JSON text encoded as UTF-8, and to create an in-memory document object model (DOM), that is read-only, for random access of the JSON elements within a structured view of the data. Commonly Used Types: diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Nodes/JsonValue.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Nodes/JsonValue.cs index 50715c5bb4217b..241a14277c631c 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Nodes/JsonValue.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Nodes/JsonValue.cs @@ -14,7 +14,7 @@ namespace System.Text.Json.Nodes public abstract partial class JsonValue : JsonNode { internal const string CreateUnreferencedCodeMessage = "Creating JsonValue instances with non-primitive types is not compatible with trimming. It can result in non-primitive types being serialized, which may have their members trimmed."; - internal const string CreateDynamicCodeMessage = "Creating JsonValue instances with non-primitive types is not compatible with runtime code generation. Use System.Text.Json source generation for native AOT applications."; + internal const string CreateDynamicCodeMessage = "Creating JsonValue instances with non-primitive types requires dynamically generating code at runtime."; private protected JsonValue(JsonNodeOptions? options = null) : base(options) { } diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Nodes/JsonValueNotTrimmable.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Nodes/JsonValueNotTrimmable.cs index c5bdd0154adc4c..611cfb8a87e0d7 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Nodes/JsonValueNotTrimmable.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Nodes/JsonValueNotTrimmable.cs @@ -8,16 +8,14 @@ namespace System.Text.Json.Nodes /// /// Not trim-safe since it calls JsonSerializer.Serialize(JsonSerializerOptions). /// + [RequiresDynamicCode(JsonSerializer.SerializationRequiresDynamicCodeMessage)] internal sealed partial class JsonValueNotTrimmable : JsonValue { [RequiresUnreferencedCode(JsonSerializer.SerializationUnreferencedCodeMessage)] - [RequiresDynamicCode(JsonSerializer.SerializationRequiresDynamicCodeMessage)] public JsonValueNotTrimmable(TValue value, JsonNodeOptions? options = null) : base(value, options) { } [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "The ctor is marked RequiresUnreferencedCode.")] - [UnconditionalSuppressMessage("AotAnalysis", "IL3050:RequiresDynamicCode", - Justification = "The ctor is marked RequiresDynamicCode.")] public override void WriteTo(Utf8JsonWriter writer, JsonSerializerOptions? options = null) { if (writer is null) diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/IAsyncEnumerableConverterFactory.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/IAsyncEnumerableConverterFactory.cs index c657cd453502b4..6f3b87f6a0e55f 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/IAsyncEnumerableConverterFactory.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/IAsyncEnumerableConverterFactory.cs @@ -12,18 +12,16 @@ namespace System.Text.Json.Serialization /// /// Converter for streaming values. /// + [RequiresDynamicCode(JsonSerializer.SerializationRequiresDynamicCodeMessage)] internal sealed class IAsyncEnumerableConverterFactory : JsonConverterFactory { [RequiresUnreferencedCode(JsonSerializer.SerializationUnreferencedCodeMessage)] - [RequiresDynamicCode(JsonSerializer.SerializationRequiresDynamicCodeMessage)] public IAsyncEnumerableConverterFactory() { } public override bool CanConvert(Type typeToConvert) => GetAsyncEnumerableInterface(typeToConvert) is not null; [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "The ctor is marked RequiresUnreferencedCode.")] - [UnconditionalSuppressMessage("AotAnalysis", "IL3050:RequiresDynamicCode", - Justification = "The ctor is marked RequiresDynamicCode.")] public override JsonConverter CreateConverter(Type typeToConvert, JsonSerializerOptions options) { Type? asyncEnumerableInterface = GetAsyncEnumerableInterface(typeToConvert); diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/IEnumerableConverterFactory.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/IEnumerableConverterFactory.cs index bd11ad1a5630a9..a6f008d0f9ed5f 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/IEnumerableConverterFactory.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/IEnumerableConverterFactory.cs @@ -14,6 +14,7 @@ namespace System.Text.Json.Serialization.Converters /// /// Converter factory for all IEnumerable types. /// + [RequiresDynamicCode(JsonSerializer.SerializationRequiresDynamicCodeMessage)] internal sealed class IEnumerableConverterFactory : JsonConverterFactory { private static readonly IDictionaryConverter s_converterForIDictionary = new IDictionaryConverter(); @@ -21,7 +22,6 @@ internal sealed class IEnumerableConverterFactory : JsonConverterFactory private static readonly IListConverter s_converterForIList = new IListConverter(); [RequiresUnreferencedCode(JsonSerializer.SerializationUnreferencedCodeMessage)] - [RequiresDynamicCode(JsonSerializer.SerializationRequiresDynamicCodeMessage)] public IEnumerableConverterFactory() { } public override bool CanConvert(Type typeToConvert) @@ -31,8 +31,6 @@ public override bool CanConvert(Type typeToConvert) [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "The ctor is marked RequiresUnreferencedCode.")] - [UnconditionalSuppressMessage("AotAnalysis", "IL3050:RequiresDynamicCode", - Justification = "The ctor is marked RequiresDynamicCode.")] public override JsonConverter CreateConverter(Type typeToConvert, JsonSerializerOptions options) { Type converterType; diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/FSharp/FSharpTypeConverterFactory.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/FSharp/FSharpTypeConverterFactory.cs index 75d7845cfff5b0..f42adbc31fe409 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/FSharp/FSharpTypeConverterFactory.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/FSharp/FSharpTypeConverterFactory.cs @@ -8,26 +8,22 @@ namespace System.Text.Json.Serialization.Converters { + [RequiresDynamicCode(FSharpCoreReflectionProxy.FSharpCoreUnreferencedCodeMessage)] internal sealed class FSharpTypeConverterFactory : JsonConverterFactory { [RequiresUnreferencedCode(FSharpCoreReflectionProxy.FSharpCoreUnreferencedCodeMessage)] - [RequiresDynamicCode(FSharpCoreReflectionProxy.FSharpCoreUnreferencedCodeMessage)] public FSharpTypeConverterFactory() { } private ObjectConverterFactory? _recordConverterFactory; [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "The ctor is marked RequiresUnreferencedCode.")] - [UnconditionalSuppressMessage("AotAnalysis", "IL3050:RequiresDynamicCode", - Justification = "The ctor is marked RequiresDynamicCode.")] public override bool CanConvert(Type typeToConvert) => FSharpCoreReflectionProxy.IsFSharpType(typeToConvert) && FSharpCoreReflectionProxy.Instance.DetectFSharpKind(typeToConvert) is not FSharpKind.Unrecognized; [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "The ctor is marked RequiresUnreferencedCode.")] - [UnconditionalSuppressMessage("AotAnalysis", "IL3050:RequiresDynamicCode", - Justification = "The ctor is marked RequiresDynamicCode.")] public override JsonConverter? CreateConverter(Type typeToConvert, JsonSerializerOptions options) { Debug.Assert(CanConvert(typeToConvert)); diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Object/ObjectConverterFactory.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Object/ObjectConverterFactory.cs index e288b2f4dfc0fe..a7e59e5146c0be 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Object/ObjectConverterFactory.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Object/ObjectConverterFactory.cs @@ -13,13 +13,13 @@ namespace System.Text.Json.Serialization.Converters /// /// Converter factory for all object-based types (non-enumerable and non-primitive). /// + [RequiresDynamicCode(JsonSerializer.SerializationRequiresDynamicCodeMessage)] internal sealed class ObjectConverterFactory : JsonConverterFactory { // Need to toggle this behavior when generating converters for F# struct records. private readonly bool _useDefaultConstructorInUnannotatedStructs; [RequiresUnreferencedCode(JsonSerializer.SerializationUnreferencedCodeMessage)] - [RequiresDynamicCode(JsonSerializer.SerializationRequiresDynamicCodeMessage)] public ObjectConverterFactory(bool useDefaultConstructorInUnannotatedStructs = true) { _useDefaultConstructorInUnannotatedStructs = useDefaultConstructorInUnannotatedStructs; @@ -37,8 +37,6 @@ public override bool CanConvert(Type typeToConvert) Justification = "The ctor is marked RequiresUnreferencedCode.")] [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2067:UnrecognizedReflectionPattern", Justification = "The ctor is marked RequiresUnreferencedCode.")] - [UnconditionalSuppressMessage("AotAnalysis", "IL3050:RequiresDynamicCode", - Justification = "The ctor is marked RequiresDynamicCode.")] public override JsonConverter CreateConverter(Type typeToConvert, JsonSerializerOptions options) { if (typeToConvert.IsKeyValuePair()) @@ -102,7 +100,6 @@ public override JsonConverter CreateConverter(Type typeToConvert, JsonSerializer return converter; } - [RequiresDynamicCode(JsonSerializer.SerializationRequiresDynamicCodeMessage)] private static JsonConverter CreateKeyValuePairConverter(Type type) { Debug.Assert(type.IsKeyValuePair()); diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/EnumConverterFactory.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/EnumConverterFactory.cs index 1aefae88921605..2fe950eac54b6e 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/EnumConverterFactory.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/EnumConverterFactory.cs @@ -5,9 +5,9 @@ namespace System.Text.Json.Serialization.Converters { + [RequiresDynamicCode(JsonSerializer.SerializationRequiresDynamicCodeMessage)] internal sealed class EnumConverterFactory : JsonConverterFactory { - [RequiresDynamicCode(JsonSerializer.SerializationRequiresDynamicCodeMessage)] public EnumConverterFactory() { } @@ -30,8 +30,6 @@ internal static JsonConverter Create(Type enumType, EnumConverterOptions convert [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2055:MakeGenericType", Justification = "'EnumConverter where T : struct' implies 'T : new()', so the trimmer is warning calling MakeGenericType here because enumType's constructors are not annotated. " + "But EnumConverter doesn't call new T(), so this is safe.")] - [UnconditionalSuppressMessage("AotAnalysis", "IL3050:RequiresDynamicCode", Justification = "The factory constructors are only invoked in the context of reflection serialization code paths " + - "and are marked RequiresDynamicCode")] [return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] private static Type GetEnumConverterType(Type enumType) => typeof(EnumConverter<>).MakeGenericType(enumType); } diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/NullableConverterFactory.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/NullableConverterFactory.cs index 029a1068663b88..2777b57c45150c 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/NullableConverterFactory.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/NullableConverterFactory.cs @@ -8,9 +8,9 @@ namespace System.Text.Json.Serialization.Converters { + [RequiresDynamicCode(JsonSerializer.SerializationRequiresDynamicCodeMessage)] internal sealed class NullableConverterFactory : JsonConverterFactory { - [RequiresDynamicCode(JsonSerializer.SerializationRequiresDynamicCodeMessage)] public NullableConverterFactory() { } @@ -51,8 +51,6 @@ public static JsonConverter CreateValueConverter(Type valueTypeToConvert, JsonCo [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2055:MakeGenericType", Justification = "'NullableConverter where T : struct' implies 'T : new()', so the trimmer is warning calling MakeGenericType here because valueTypeToConvert's constructors are not annotated. " + "But NullableConverter doesn't call new T(), so this is safe.")] - [UnconditionalSuppressMessage("AotAnalysis", "IL3050:RequiresDynamicCode", Justification = "The factory constructors are only invoked in the context of reflection serialization code paths " + - "and are marked RequiresDynamicCode")] [return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] private static Type GetNullableConverterType(Type valueTypeToConvert) => typeof(NullableConverter<>).MakeGenericType(valueTypeToConvert); } diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/UnsupportedTypeConverterFactory.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/UnsupportedTypeConverterFactory.cs index e6bd71ea2e8aac..c6c7520b26a0c4 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/UnsupportedTypeConverterFactory.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/UnsupportedTypeConverterFactory.cs @@ -7,9 +7,9 @@ namespace System.Text.Json.Serialization.Converters { + [RequiresDynamicCode(JsonSerializer.SerializationRequiresDynamicCodeMessage)] internal sealed class UnsupportedTypeConverterFactory : JsonConverterFactory { - [RequiresDynamicCode(JsonSerializer.SerializationRequiresDynamicCodeMessage)] public UnsupportedTypeConverterFactory() { } @@ -46,8 +46,6 @@ public override bool CanConvert(Type type) #endif } - [UnconditionalSuppressMessage("AotAnalysis", "IL3050:RequiresDynamicCode", Justification = "The factory constructors are only invoked in the context of reflection serialization code paths " + - "and are marked RequiresDynamicCode")] public override JsonConverter CreateConverter(Type type, JsonSerializerOptions options) { JsonConverter converter = (JsonConverter)Activator.CreateInstance( diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializerOptions.Converters.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializerOptions.Converters.cs index 7ec6e9cfd1cb5a..bdfec62a7e7f54 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializerOptions.Converters.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializerOptions.Converters.cs @@ -323,6 +323,8 @@ private JsonConverter GetConverterFromType(Type typeToConvert) return converter; } + [UnconditionalSuppressMessage("AotAnalysis", "IL3050:RequiresDynamicCode", Justification = "The factory constructors are only invoked in the context of reflection serialization code paths " + + "and are marked RequiresDynamicCode")] private JsonConverter GetConverterFromAttribute(JsonConverterAttribute converterAttribute, Type typeToConvert, Type classTypeAttributeIsOn, MemberInfo? memberInfo) { JsonConverter? converter; diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonStringEnumConverter.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonStringEnumConverter.cs index d580d1d54cc0ca..ceed96e37606db 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonStringEnumConverter.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonStringEnumConverter.cs @@ -12,6 +12,7 @@ namespace System.Text.Json.Serialization /// /// Reading is case insensitive, writing can be customized via a . /// + [RequiresDynamicCode(JsonSerializer.SerializationRequiresDynamicCodeMessage)] public class JsonStringEnumConverter : JsonConverterFactory { private readonly JsonNamingPolicy? _namingPolicy; @@ -21,7 +22,6 @@ public class JsonStringEnumConverter : JsonConverterFactory /// Constructor. Creates the with the /// default naming policy and allows integer values. /// - [RequiresDynamicCode(JsonSerializer.SerializationRequiresDynamicCodeMessage)] public JsonStringEnumConverter() : this(namingPolicy: null, allowIntegerValues: true) { @@ -38,7 +38,6 @@ public JsonStringEnumConverter() /// True to allow undefined enum values. When true, if an enum value isn't /// defined it will output as a number rather than a string. /// - [RequiresDynamicCode(JsonSerializer.SerializationRequiresDynamicCodeMessage)] public JsonStringEnumConverter(JsonNamingPolicy? namingPolicy = null, bool allowIntegerValues = true) { _namingPolicy = namingPolicy; diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/ReflectionEmitCachingMemberAccessor.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/ReflectionEmitCachingMemberAccessor.cs index 224223b6879e3a..a089070dde397b 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/ReflectionEmitCachingMemberAccessor.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/ReflectionEmitCachingMemberAccessor.cs @@ -8,12 +8,10 @@ namespace System.Text.Json.Serialization.Metadata { + [RequiresDynamicCode(JsonSerializer.SerializationRequiresDynamicCodeMessage)] internal sealed partial class ReflectionEmitCachingMemberAccessor : MemberAccessor { - [RequiresDynamicCode(JsonSerializer.SerializationRequiresDynamicCodeMessage)] internal ReflectionEmitCachingMemberAccessor() { } - [UnconditionalSuppressMessage("AotAnalysis", "IL3050:RequiresDynamicCode", - Justification = "The ctor is marked RequiresDynamicCode.")] private static readonly ReflectionEmitMemberAccessor s_sourceAccessor = new(); private static readonly Cache<(string id, Type declaringType, MemberInfo? member)> s_cache = new(slidingExpiration: TimeSpan.FromMilliseconds(1000), evictionInterval: TimeSpan.FromMilliseconds(200)); @@ -39,7 +37,6 @@ public override Action CreateFieldSetter(FieldInfo => s_cache.GetOrAdd((nameof(CreateFieldSetter), typeof(TProperty), fieldInfo), static key => s_sourceAccessor.CreateFieldSetter((FieldInfo)key.member!)); [RequiresUnreferencedCode(IEnumerableConverterFactoryHelpers.ImmutableConvertersUnreferencedCodeMessage)] - [RequiresDynamicCode(IEnumerableConverterFactoryHelpers.ImmutableConvertersUnreferencedCodeMessage)] public override Func>, TCollection> CreateImmutableDictionaryCreateRangeDelegate() => s_cache.GetOrAdd((nameof(CreateImmutableDictionaryCreateRangeDelegate), typeof((TCollection, TKey, TValue)), null), [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", @@ -49,7 +46,6 @@ public override Func>, TCollection> Creat #pragma warning restore IL2026 [RequiresUnreferencedCode(IEnumerableConverterFactoryHelpers.ImmutableConvertersUnreferencedCodeMessage)] - [RequiresDynamicCode(IEnumerableConverterFactoryHelpers.ImmutableConvertersUnreferencedCodeMessage)] public override Func, TCollection> CreateImmutableEnumerableCreateRangeDelegate() => s_cache.GetOrAdd((nameof(CreateImmutableEnumerableCreateRangeDelegate), typeof((TCollection, TElement)), null), [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/ReflectionEmitMemberAccessor.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/ReflectionEmitMemberAccessor.cs index d2e6978b941931..b4efeb3ce472d1 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/ReflectionEmitMemberAccessor.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/ReflectionEmitMemberAccessor.cs @@ -10,14 +10,12 @@ namespace System.Text.Json.Serialization.Metadata { + [RequiresDynamicCode(JsonSerializer.SerializationRequiresDynamicCodeMessage)] internal sealed class ReflectionEmitMemberAccessor : MemberAccessor { - [RequiresDynamicCode(JsonSerializer.SerializationRequiresDynamicCodeMessage)] internal ReflectionEmitMemberAccessor() { } - [UnconditionalSuppressMessage("AotAnalysis", "IL3050:RequiresDynamicCode", - Justification = "The ctor is marked RequiresDynamicCode.")] public override JsonTypeInfo.ConstructorDelegate? CreateConstructor( [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type type) { @@ -67,12 +65,9 @@ internal ReflectionEmitMemberAccessor() { } return (JsonTypeInfo.ConstructorDelegate)dynamicMethod.CreateDelegate(typeof(JsonTypeInfo.ConstructorDelegate)); } - [UnconditionalSuppressMessage("AotAnalysis", "IL3050:RequiresDynamicCode", - Justification = "The ctor is marked RequiresDynamicCode.")] public override Func? CreateParameterizedConstructor(ConstructorInfo constructor) => CreateDelegate>(CreateParameterizedConstructor(constructor)); - [RequiresDynamicCode(JsonSerializer.SerializationRequiresDynamicCodeMessage)] private static DynamicMethod? CreateParameterizedConstructor(ConstructorInfo constructor) { Type? type = constructor.DeclaringType; @@ -114,14 +109,11 @@ internal ReflectionEmitMemberAccessor() { } return dynamicMethod; } - [UnconditionalSuppressMessage("AotAnalysis", "IL3050:RequiresDynamicCode", - Justification = "The ctor is marked RequiresDynamicCode.")] public override JsonTypeInfo.ParameterizedConstructorDelegate? CreateParameterizedConstructor(ConstructorInfo constructor) => CreateDelegate>( CreateParameterizedConstructor(constructor, typeof(TArg0), typeof(TArg1), typeof(TArg2), typeof(TArg3))); - [RequiresDynamicCode(JsonSerializer.SerializationRequiresDynamicCodeMessage)] private static DynamicMethod? CreateParameterizedConstructor(ConstructorInfo constructor, Type parameterType1, Type parameterType2, Type parameterType3, Type parameterType4) { Type? type = constructor.DeclaringType; @@ -163,12 +155,9 @@ public override JsonTypeInfo.ParameterizedConstructorDelegate CreateAddMethodDelegate<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)] TCollection>() => CreateDelegate>(CreateAddMethodDelegate(typeof(TCollection))); - [RequiresDynamicCode(JsonSerializer.SerializationRequiresDynamicCodeMessage)] private static DynamicMethod CreateAddMethodDelegate( [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)] Type collectionType) { @@ -199,7 +188,6 @@ public override Func, TCollection> CreateImmutableEnumerab CreateImmutableEnumerableCreateRangeDelegate(typeof(TCollection), typeof(TElement), typeof(IEnumerable))); [RequiresUnreferencedCode(IEnumerableConverterFactoryHelpers.ImmutableConvertersUnreferencedCodeMessage)] - [RequiresDynamicCode(IEnumerableConverterFactoryHelpers.ImmutableConvertersUnreferencedCodeMessage)] private static DynamicMethod CreateImmutableEnumerableCreateRangeDelegate(Type collectionType, Type elementType, Type enumerableType) { MethodInfo realMethod = collectionType.GetImmutableEnumerableCreateRangeMethod(elementType); @@ -227,7 +215,6 @@ public override Func>, TCollection> Creat CreateImmutableDictionaryCreateRangeDelegate(typeof(TCollection), typeof(TKey), typeof(TValue), typeof(IEnumerable>))); [RequiresUnreferencedCode(IEnumerableConverterFactoryHelpers.ImmutableConvertersUnreferencedCodeMessage)] - [RequiresDynamicCode(IEnumerableConverterFactoryHelpers.ImmutableConvertersUnreferencedCodeMessage)] private static DynamicMethod CreateImmutableDictionaryCreateRangeDelegate(Type collectionType, Type keyType, Type valueType, Type enumerableType) { MethodInfo realMethod = collectionType.GetImmutableDictionaryCreateRangeMethod(keyType, valueType); @@ -248,12 +235,9 @@ private static DynamicMethod CreateImmutableDictionaryCreateRangeDelegate(Type c return dynamicMethod; } - [UnconditionalSuppressMessage("AotAnalysis", "IL3050:RequiresDynamicCode", - Justification = "The ctor is marked RequiresDynamicCode.")] public override Func CreatePropertyGetter(PropertyInfo propertyInfo) => CreateDelegate>(CreatePropertyGetter(propertyInfo, typeof(TProperty))); - [RequiresDynamicCode(JsonSerializer.SerializationRequiresDynamicCodeMessage)] private static DynamicMethod CreatePropertyGetter(PropertyInfo propertyInfo, Type runtimePropertyType) { MethodInfo? realMethod = propertyInfo.GetMethod; @@ -297,12 +281,9 @@ private static DynamicMethod CreatePropertyGetter(PropertyInfo propertyInfo, Typ return dynamicMethod; } - [UnconditionalSuppressMessage("AotAnalysis", "IL3050:RequiresDynamicCode", - Justification = "The ctor is marked RequiresDynamicCode.")] public override Action CreatePropertySetter(PropertyInfo propertyInfo) => CreateDelegate>(CreatePropertySetter(propertyInfo, typeof(TProperty))); - [RequiresDynamicCode(JsonSerializer.SerializationRequiresDynamicCodeMessage)] private static DynamicMethod CreatePropertySetter(PropertyInfo propertyInfo, Type runtimePropertyType) { MethodInfo? realMethod = propertyInfo.SetMethod; @@ -338,12 +319,9 @@ private static DynamicMethod CreatePropertySetter(PropertyInfo propertyInfo, Typ return dynamicMethod; } - [UnconditionalSuppressMessage("AotAnalysis", "IL3050:RequiresDynamicCode", - Justification = "The ctor is marked RequiresDynamicCode.")] public override Func CreateFieldGetter(FieldInfo fieldInfo) => CreateDelegate>(CreateFieldGetter(fieldInfo, typeof(TProperty))); - [RequiresDynamicCode(JsonSerializer.SerializationRequiresDynamicCodeMessage)] private static DynamicMethod CreateFieldGetter(FieldInfo fieldInfo, Type runtimeFieldType) { Type? declaringType = fieldInfo.DeclaringType; @@ -375,12 +353,9 @@ private static DynamicMethod CreateFieldGetter(FieldInfo fieldInfo, Type runtime return dynamicMethod; } - [UnconditionalSuppressMessage("AotAnalysis", "IL3050:RequiresDynamicCode", - Justification = "The ctor is marked RequiresDynamicCode.")] public override Action CreateFieldSetter(FieldInfo fieldInfo) => CreateDelegate>(CreateFieldSetter(fieldInfo, typeof(TProperty))); - [RequiresDynamicCode(JsonSerializer.SerializationRequiresDynamicCodeMessage)] private static DynamicMethod CreateFieldSetter(FieldInfo fieldInfo, Type runtimeFieldType) { Type? declaringType = fieldInfo.DeclaringType; @@ -409,7 +384,6 @@ private static DynamicMethod CreateFieldSetter(FieldInfo fieldInfo, Type runtime return dynamicMethod; } - [RequiresDynamicCode(JsonSerializer.SerializationRequiresDynamicCodeMessage)] private static DynamicMethod CreateGetterMethod(string memberName, Type memberType) => new DynamicMethod( memberName + "Getter", @@ -418,7 +392,6 @@ private static DynamicMethod CreateGetterMethod(string memberName, Type memberTy typeof(ReflectionEmitMemberAccessor).Module, skipVisibility: true); - [RequiresDynamicCode(JsonSerializer.SerializationRequiresDynamicCodeMessage)] private static DynamicMethod CreateSetterMethod(string memberName, Type memberType) => new DynamicMethod( memberName + "Setter", From 086cc8d61f1e2279a94d02bc20c80af64f16b3fd Mon Sep 17 00:00:00 2001 From: Lakshan Fernando Date: Thu, 28 Apr 2022 14:20:06 -0700 Subject: [PATCH 7/9] using consistent terminology in the annotation --- src/libraries/System.Text.Json/ref/System.Text.Json.cs | 6 +++--- .../src/System/Text/Json/Nodes/JsonValue.cs | 2 +- .../Json/Serialization/JsonSerializerOptions.Converters.cs | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/libraries/System.Text.Json/ref/System.Text.Json.cs b/src/libraries/System.Text.Json/ref/System.Text.Json.cs index 592410e3073238..6a188599ee3ae4 100644 --- a/src/libraries/System.Text.Json/ref/System.Text.Json.cs +++ b/src/libraries/System.Text.Json/ref/System.Text.Json.cs @@ -360,7 +360,7 @@ public JsonSerializerOptions(System.Text.Json.JsonSerializerOptions options) { } public bool WriteIndented { get { throw null; } set { } } public void AddContext() where TContext : System.Text.Json.Serialization.JsonSerializerContext, new() { } [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Getting a converter for a type may require reflection which depends on unreferenced code.")] - [System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Getting a converter for a type may require reflection which depends on dynamic code.")] + [System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Getting a converter for a type may require reflection which depends on runtime code generation.")] public System.Text.Json.Serialization.JsonConverter GetConverter(System.Type typeToConvert) { throw null; } } public enum JsonTokenType : byte @@ -609,7 +609,7 @@ public JsonArray(params System.Text.Json.Nodes.JsonNode?[] items) { } bool System.Collections.Generic.ICollection.IsReadOnly { get { throw null; } } public void Add(System.Text.Json.Nodes.JsonNode? item) { } [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Creating JsonValue instances with non-primitive types is not compatible with trimming. It can result in non-primitive types being serialized, which may have their members trimmed.")] - [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("Creating JsonValue instances with non-primitive types requires dynamically generating code at runtime.")] + [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("Creating JsonValue instances with non-primitive types requires generating code at runtime.")] public void Add(T? value) { } public void Clear() { } public bool Contains(System.Text.Json.Nodes.JsonNode? item) { throw null; } @@ -802,7 +802,7 @@ public abstract partial class JsonValue : System.Text.Json.Nodes.JsonNode public static System.Text.Json.Nodes.JsonValue Create(ulong value, System.Text.Json.Nodes.JsonNodeOptions? options = default(System.Text.Json.Nodes.JsonNodeOptions?)) { throw null; } public static System.Text.Json.Nodes.JsonValue? Create(T? value, System.Text.Json.Serialization.Metadata.JsonTypeInfo jsonTypeInfo, System.Text.Json.Nodes.JsonNodeOptions? options = default(System.Text.Json.Nodes.JsonNodeOptions?)) { throw null; } [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Creating JsonValue instances with non-primitive types is not compatible with trimming. It can result in non-primitive types being serialized, which may have their members trimmed. Use the overload that takes a JsonTypeInfo, or make sure all of the required types are preserved.")] - [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("Creating JsonValue instances with non-primitive types requires dynamically generating code at runtime.")] + [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("Creating JsonValue instances with non-primitive types requires generating code at runtime.")] public static System.Text.Json.Nodes.JsonValue? Create(T? value, System.Text.Json.Nodes.JsonNodeOptions? options = default(System.Text.Json.Nodes.JsonNodeOptions?)) { throw null; } public abstract bool TryGetValue([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] out T? value); } diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Nodes/JsonValue.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Nodes/JsonValue.cs index 241a14277c631c..9458841277f3ae 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Nodes/JsonValue.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Nodes/JsonValue.cs @@ -14,7 +14,7 @@ namespace System.Text.Json.Nodes public abstract partial class JsonValue : JsonNode { internal const string CreateUnreferencedCodeMessage = "Creating JsonValue instances with non-primitive types is not compatible with trimming. It can result in non-primitive types being serialized, which may have their members trimmed."; - internal const string CreateDynamicCodeMessage = "Creating JsonValue instances with non-primitive types requires dynamically generating code at runtime."; + internal const string CreateDynamicCodeMessage = "Creating JsonValue instances with non-primitive types requires generating code at runtime."; private protected JsonValue(JsonNodeOptions? options = null) : base(options) { } diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializerOptions.Converters.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializerOptions.Converters.cs index bdfec62a7e7f54..8fa11f6cfb836e 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializerOptions.Converters.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializerOptions.Converters.cs @@ -216,7 +216,7 @@ internal JsonConverter GetConverterFromMember(Type? parentClassType, Type proper /// for or its serializable members. /// [RequiresUnreferencedCode("Getting a converter for a type may require reflection which depends on unreferenced code.")] - [RequiresDynamicCode("Getting a converter for a type may require reflection which depends on dynamic code.")] + [RequiresDynamicCode("Getting a converter for a type may require reflection which depends on runtime code generation.")] public JsonConverter GetConverter(Type typeToConvert) { if (typeToConvert is null) From 5b8f6cff837a532719382755d4893ad54d7a2d5f Mon Sep 17 00:00:00 2001 From: Lakshan Fernando Date: Fri, 29 Apr 2022 11:05:29 -0700 Subject: [PATCH 8/9] FB minus the suppression change --- .../Converters/Value/NullableConverterFactory.cs | 4 ---- .../Converters/Value/UnsupportedTypeConverterFactory.cs | 4 ---- .../System/Text/Json/Serialization/JsonSerializerOptions.cs | 3 ++- .../Metadata/ReflectionEmitCachingMemberAccessor.cs | 1 - .../Serialization/Metadata/ReflectionEmitMemberAccessor.cs | 3 --- 5 files changed, 2 insertions(+), 13 deletions(-) diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/NullableConverterFactory.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/NullableConverterFactory.cs index 2777b57c45150c..cbc89a4fb7bba6 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/NullableConverterFactory.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/NullableConverterFactory.cs @@ -11,10 +11,6 @@ namespace System.Text.Json.Serialization.Converters [RequiresDynamicCode(JsonSerializer.SerializationRequiresDynamicCodeMessage)] internal sealed class NullableConverterFactory : JsonConverterFactory { - public NullableConverterFactory() - { - } - public override bool CanConvert(Type typeToConvert) { return typeToConvert.IsNullableOfT(); diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/UnsupportedTypeConverterFactory.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/UnsupportedTypeConverterFactory.cs index c6c7520b26a0c4..71abc44176b809 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/UnsupportedTypeConverterFactory.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/UnsupportedTypeConverterFactory.cs @@ -10,10 +10,6 @@ namespace System.Text.Json.Serialization.Converters [RequiresDynamicCode(JsonSerializer.SerializationRequiresDynamicCodeMessage)] internal sealed class UnsupportedTypeConverterFactory : JsonConverterFactory { - public UnsupportedTypeConverterFactory() - { - } - public override bool CanConvert(Type type) { // If a type is added, also add to the SourceGeneration project. diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializerOptions.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializerOptions.cs index fd1b4ac9469192..e444cc9c27b07e 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializerOptions.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializerOptions.cs @@ -572,7 +572,8 @@ internal JsonSerializerContext? JsonSerializerContext // The cached value used to determine if ReferenceHandler should use Preserve or IgnoreCycles semanitcs or None of them. internal ReferenceHandlingStrategy ReferenceHandlingStrategy = ReferenceHandlingStrategy.None; // Workaround https://github.com/dotnet/linker/issues/2715 - [UnconditionalSuppressMessage("AotAnalysis", "IL3050:RequiresDynamicCode", Justification = "Dyanmic path is guarded by the runtime feature switch.")] + [UnconditionalSuppressMessage("AotAnalysis", "IL3050:RequiresDynamicCode", + Justification = "Dynamic path is guarded by the runtime feature switch.")] internal MemberAccessor MemberAccessorStrategy { get diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/ReflectionEmitCachingMemberAccessor.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/ReflectionEmitCachingMemberAccessor.cs index a089070dde397b..d35e6e9e2cdaeb 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/ReflectionEmitCachingMemberAccessor.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/ReflectionEmitCachingMemberAccessor.cs @@ -11,7 +11,6 @@ namespace System.Text.Json.Serialization.Metadata [RequiresDynamicCode(JsonSerializer.SerializationRequiresDynamicCodeMessage)] internal sealed partial class ReflectionEmitCachingMemberAccessor : MemberAccessor { - internal ReflectionEmitCachingMemberAccessor() { } private static readonly ReflectionEmitMemberAccessor s_sourceAccessor = new(); private static readonly Cache<(string id, Type declaringType, MemberInfo? member)> s_cache = new(slidingExpiration: TimeSpan.FromMilliseconds(1000), evictionInterval: TimeSpan.FromMilliseconds(200)); diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/ReflectionEmitMemberAccessor.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/ReflectionEmitMemberAccessor.cs index b4efeb3ce472d1..6a6f612363f6dc 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/ReflectionEmitMemberAccessor.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/ReflectionEmitMemberAccessor.cs @@ -13,9 +13,6 @@ namespace System.Text.Json.Serialization.Metadata [RequiresDynamicCode(JsonSerializer.SerializationRequiresDynamicCodeMessage)] internal sealed class ReflectionEmitMemberAccessor : MemberAccessor { - - internal ReflectionEmitMemberAccessor() { } - public override JsonTypeInfo.ConstructorDelegate? CreateConstructor( [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type type) { From 3eff9c351c96f34994d35fc09c85e56f0d6aa100 Mon Sep 17 00:00:00 2001 From: Lakshan Fernando Date: Wed, 4 May 2022 17:22:12 -0700 Subject: [PATCH 9/9] reverting to pre-converter annotation status --- .../Text/Json/Serialization/JsonSerializerOptions.Converters.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializerOptions.Converters.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializerOptions.Converters.cs index 8fa11f6cfb836e..58e81d7afe7504 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializerOptions.Converters.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializerOptions.Converters.cs @@ -323,6 +323,7 @@ private JsonConverter GetConverterFromType(Type typeToConvert) return converter; } + // This suppression needs to be removed. https://github.com/dotnet/runtime/issues/68878 [UnconditionalSuppressMessage("AotAnalysis", "IL3050:RequiresDynamicCode", Justification = "The factory constructors are only invoked in the context of reflection serialization code paths " + "and are marked RequiresDynamicCode")] private JsonConverter GetConverterFromAttribute(JsonConverterAttribute converterAttribute, Type typeToConvert, Type classTypeAttributeIsOn, MemberInfo? memberInfo)