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..6a188599ee3ae4 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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.")] - 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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; } } @@ -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 runtime code generation.")] 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 requires generating code at runtime.")] 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 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); } @@ -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() { } @@ -933,6 +971,7 @@ 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 { public JsonStringEnumConverter() { } 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 3e4e061785d008..9fa16ff5f2f42f 100644 --- a/src/libraries/System.Text.Json/ref/System.Text.Json.csproj +++ b/src/libraries/System.Text.Json/ref/System.Text.Json.csproj @@ -22,6 +22,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 fbf4ad0135d462..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: @@ -343,6 +345,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..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,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.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 18700433da605d..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,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 requires generating code at runtime."; private protected JsonValue(JsonNodeOptions? options = null) : base(options) { } @@ -28,6 +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(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/Nodes/JsonValueNotTrimmable.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Nodes/JsonValueNotTrimmable.cs index 203ffd7466ab6a..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,13 +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)] 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.")] 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..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 @@ -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; @@ -12,6 +12,7 @@ namespace System.Text.Json.Serialization /// /// Converter for streaming values. /// + [RequiresDynamicCode(JsonSerializer.SerializationRequiresDynamicCodeMessage)] internal sealed class IAsyncEnumerableConverterFactory : JsonConverterFactory { [RequiresUnreferencedCode(JsonSerializer.SerializationUnreferencedCodeMessage)] 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..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(); 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..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 @@ -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; @@ -8,6 +8,7 @@ namespace System.Text.Json.Serialization.Converters { + [RequiresDynamicCode(FSharpCoreReflectionProxy.FSharpCoreUnreferencedCodeMessage)] internal sealed class FSharpTypeConverterFactory : JsonConverterFactory { [RequiresUnreferencedCode(FSharpCoreReflectionProxy.FSharpCoreUnreferencedCodeMessage)] @@ -16,13 +17,13 @@ public FSharpTypeConverterFactory() { } private ObjectConverterFactory? _recordConverterFactory; [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", - Justification = "The ctor is marked with RequiresUnreferencedCode.")] + Justification = "The ctor is marked RequiresUnreferencedCode.")] 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.")] 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..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,6 +13,7 @@ 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. 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..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,6 +5,7 @@ namespace System.Text.Json.Serialization.Converters { + [RequiresDynamicCode(JsonSerializer.SerializationRequiresDynamicCodeMessage)] internal sealed class EnumConverterFactory : JsonConverterFactory { 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 469205e4d99f6c..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 @@ -8,6 +8,7 @@ namespace System.Text.Json.Serialization.Converters { + [RequiresDynamicCode(JsonSerializer.SerializationRequiresDynamicCodeMessage)] internal sealed class NullableConverterFactory : JsonConverterFactory { public override bool CanConvert(Type typeToConvert) 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..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 @@ -1,11 +1,13 @@ // 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; namespace System.Text.Json.Serialization.Converters { + [RequiresDynamicCode(JsonSerializer.SerializationRequiresDynamicCodeMessage)] internal sealed class UnsupportedTypeConverterFactory : JsonConverterFactory { public override bool CanConvert(Type type) 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..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 @@ -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 System.Text.Json source generation 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..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 @@ -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 runtime code generation.")] public JsonConverter GetConverter(Type typeToConvert) { if (typeToConvert is null) @@ -318,6 +323,9 @@ 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) { JsonConverter? converter; 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..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 @@ -571,7 +571,9 @@ 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 = "Dynamic path is guarded by the runtime feature switch.")] internal MemberAccessor MemberAccessorStrategy { get @@ -604,6 +606,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..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 @@ -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(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 7d8d161acd0a35..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 @@ -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 @@ -11,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; 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..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 @@ -20,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 f45bb72f4610a0..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 @@ -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(JsonSerializer.SerializationRequiresDynamicCodeMessage)] 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..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 @@ -10,6 +10,7 @@ namespace System.Text.Json.Serialization.Metadata { + [RequiresDynamicCode(JsonSerializer.SerializationRequiresDynamicCodeMessage)] internal sealed class ReflectionEmitMemberAccessor : MemberAccessor { public override JsonTypeInfo.ConstructorDelegate? CreateConstructor( @@ -178,6 +179,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))); @@ -204,6 +206,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>))); 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..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 @@ -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) { @@ -42,7 +44,9 @@ 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() { 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..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 @@ -137,6 +137,7 @@ public override JsonTypeInfo.ParameterizedConstructorDelegate, TCollection> CreateImmutableEnumerableCreateRangeDelegate() { MethodInfo createRange = typeof(TCollection).GetImmutableEnumerableCreateRangeMethod(typeof(TElement)); @@ -145,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));