chore: Fix trimmer warnings in Uno.Extensions.Serialization - #2995
Closed
jonpryor wants to merge 1 commit into
Closed
chore: Fix trimmer warnings in Uno.Extensions.Serialization#2995jonpryor wants to merge 1 commit into
jonpryor wants to merge 1 commit into
Conversation
Enable `$(IsAotCompatible)`=true for the following projects: * `src/Uno.Extensions.Serialization/Uno.Extensions.Serialization.csproj` Address the following warnings: src/Uno.Extensions.Serialization/SystemTextJsonSerializer.cs(120,14): error IL2046: Member 'Uno.Extensions.Serialization.SystemTextJsonSerializer.ToString(Object, Type)' with 'RequiresUnreferencedCodeAttribute' implements interface member 'Uno.Extensions.Serialization.ISerializer.ToString(Object, Type)' without 'RequiresUnreferencedCodeAttribute'. 'RequiresUnreferencedCodeAttribute' annotations must match across all interface implementations or overrides. src/Uno.Extensions.Serialization/SystemTextJsonSerializer.cs(88,16): error IL2046: Member 'Uno.Extensions.Serialization.SystemTextJsonSerializer.ToString(Object, Type)' with 'RequiresUnreferencedCodeAttribute' implements interface member 'Uno.Extensions.Serialization.ISerializer.ToString(Object, Type)' without 'RequiresUnreferencedCodeAttribute'. 'RequiresUnreferencedCodeAttribute' annotations must match across all interface implementations or overrides. src/Uno.Extensions.Serialization/SystemTextJsonSerializer.cs(107,17): error IL2046: Member 'Uno.Extensions.Serialization.SystemTextJsonSerializer.FromString(String, Type)' with 'RequiresUnreferencedCodeAttribute' implements interface member 'Uno.Extensions.Serialization.ISerializer.FromString(String, Type)' without 'RequiresUnreferencedCodeAttribute'. 'RequiresUnreferencedCodeAttribute' annotations must match across all interface implementations or overrides. src/Uno.Extensions.Serialization/SystemTextJsonSerializer.cs(120,14): error IL2046: Member 'Uno.Extensions.Serialization.SystemTextJsonSerializer.FromString(String, Type)' with 'RequiresUnreferencedCodeAttribute' implements interface member 'Uno.Extensions.Serialization.ISerializer.FromString(String, Type)' without 'RequiresUnreferencedCodeAttribute'. 'RequiresUnreferencedCodeAttribute' annotations must match across all interface implementations or overrides. src/Uno.Extensions.Serialization/SystemTextJsonSerializer.cs(43,17): error IL2046: Member 'Uno.Extensions.Serialization.SystemTextJsonSerializer.FromStream(Stream, Type)' with 'RequiresUnreferencedCodeAttribute' implements interface member 'Uno.Extensions.Serialization.ISerializer.FromStream(Stream, Type)' without 'RequiresUnreferencedCodeAttribute'. 'RequiresUnreferencedCodeAttribute' annotations must match across all interface implementations or overrides. src/Uno.Extensions.Serialization/SystemTextJsonSerializer.cs(120,14): error IL2046: Member 'Uno.Extensions.Serialization.SystemTextJsonSerializer.FromStream(Stream, Type)' with 'RequiresUnreferencedCodeAttribute' implements interface member 'Uno.Extensions.Serialization.ISerializer.FromStream(Stream, Type)' without 'RequiresUnreferencedCodeAttribute'. 'RequiresUnreferencedCodeAttribute' annotations must match across all interface implementations or overrides. src/Uno.Extensions.Serialization/SystemTextJsonSerializer.cs(62,14): error IL2046: Member 'Uno.Extensions.Serialization.SystemTextJsonSerializer.ToStream(Stream, Object, Type)' with 'RequiresUnreferencedCodeAttribute' implements interface member 'Uno.Extensions.Serialization.ISerializer.ToStream(Stream, Object, Type)' without 'RequiresUnreferencedCodeAttribute'. 'RequiresUnreferencedCodeAttribute' annotations must match across all interface implementations or overrides. src/Uno.Extensions.Serialization/SystemTextJsonSerializer.cs(120,14): error IL2046: Member 'Uno.Extensions.Serialization.SystemTextJsonSerializer.ToStream(Stream, Object, Type)' with 'RequiresUnreferencedCodeAttribute' implements interface member 'Uno.Extensions.Serialization.ISerializer.ToStream(Stream, Object, Type)' without 'RequiresUnreferencedCodeAttribute'. 'RequiresUnreferencedCodeAttribute' annotations must match across all interface implementations or overrides. src/Uno.Extensions.Serialization/SystemTextJsonSerializer.cs(146,10): error IL2026: Using member 'Uno.Extensions.Serialization.SystemTextJsonSerializer.FromStream(Stream, Type)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. From JsonDeserializer: 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. src/Uno.Extensions.Serialization/SystemTextJsonSerializer.cs(157,10): error IL2026: Using member 'Uno.Extensions.Serialization.SystemTextJsonSerializer.ToString(Object, Type)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. From JsonDeserializer: 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. src/Uno.Extensions.Serialization/SystemTextJsonSerializer.cs(140,10): error IL2026: Using member 'Uno.Extensions.Serialization.SystemTextJsonSerializer.FromString(String, Type)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. From JsonDeserializer: 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. src/Uno.Extensions.Serialization/SystemTextJsonSerializer.cs(168,3): error IL2026: Using member 'Uno.Extensions.Serialization.SystemTextJsonSerializer.ToStream(Stream, Object, Type)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. From JsonDeserializer: 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. src/Uno.Extensions.Serialization/SystemTextJsonSerializer.cs(46,89): error IL3050: Using member 'System.Text.Json.JsonSerializer.Deserialize(Stream, Type, JsonSerializerOptions)' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use System.Text.Json source generation for native AOT applications. src/Uno.Extensions.Serialization/SystemTextJsonSerializer.cs(71,4): error IL3050: Using member 'System.Text.Json.JsonSerializer.Serialize(Stream, Object, Type, JsonSerializerOptions)' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use System.Text.Json source generation for native AOT applications. src/Uno.Extensions.Serialization/SystemTextJsonSerializer.cs(91,85): error IL3050: Using member 'System.Text.Json.JsonSerializer.Serialize(Object, Type, JsonSerializerOptions)' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use System.Text.Json source generation for native AOT applications. src/Uno.Extensions.Serialization/SystemTextJsonSerializer.cs(110,89): error IL3050: Using member 'System.Text.Json.JsonSerializer.Deserialize(String, Type, JsonSerializerOptions)' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use System.Text.Json source generation for native AOT applications. Add `[RequiresDynamicCode]` and/or `[RequiresUnreferencedCode]`. Note: updating `SystemTextJsonSerializer` and `SystemTextJsonSerializer<T>` to have `[RequiresDynamicCode]` and `[RequiresUnreferencedCode]` on the methods implementing `ISerializer` and `ISerializer<T>` results in warnings such as: src/Uno.Extensions.Serialization/SystemTextJsonSerializer.cs(127,14): error IL2046: Member 'Uno.Extensions.Serialization.SystemTextJsonSerializer.ToStream(Stream, Object, Type)' with 'RequiresUnreferencedCodeAttribute' implements interface member 'Uno.Extensions.Serialization.ISerializer.ToStream(Stream, Object, Type)' without 'RequiresUnreferencedCodeAttribute'. 'RequiresUnreferencedCodeAttribute' annotations must match across all interface implementations or overrides. src/Uno.Extensions.Serialization/SystemTextJsonSerializer.cs(131,14): error IL3051: Member 'Uno.Extensions.Serialization.SystemTextJsonSerializer.ToStream(Stream, Object, Type)' with 'RequiresDynamicCodeAttribute' implements interface member 'Uno.Extensions.Serialization.ISerializer.ToStream(Stream, Object, Type)' without 'RequiresDynamicCodeAttribute'. 'RequiresDynamicCodeAttribute' annotations must match across all interface implementations or overrides. The problem here is philosophical: while `SystemTextJsonSerializer` and `SystemTextJsonSerializer<T>` use `JsonSerializer` codepaths which are annotated with `[RequiresDynamicCode]` and `[RequiresUnreferencedCode]`, that doesn't mean that *all* `ISerializer` implementations should have this restriction/requirement. Use `[UnconditionalSuppressMessage]` to suppress the IL2046 and IL3051 warnings, so that we don't need to update the `ISerializer` interface.
jonpryor
enabled auto-merge
December 23, 2025 20:31
Contributor
Author
|
Superseded by #2996. |
auto-merge was automatically disabled
January 2, 2026 19:09
Pull request was closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Enable
$(IsAotCompatible)=true for the following projects:src/Uno.Extensions.Serialization/Uno.Extensions.Serialization.csprojAddress the following warnings:
Add
[RequiresDynamicCode]and/or[RequiresUnreferencedCode].Note: updating
SystemTextJsonSerializerandSystemTextJsonSerializer<T>to have[RequiresDynamicCode]and[RequiresUnreferencedCode]on the methods implementingISerializerandISerializer<T>results in warnings such as:The problem here is philosophical: while
SystemTextJsonSerializerandSystemTextJsonSerializer<T>useJsonSerializercodepaths which are annotated with[RequiresDynamicCode]and[RequiresUnreferencedCode], that doesn't mean that allISerializerimplementations should have this restriction/requirement.Use
[UnconditionalSuppressMessage]to suppress the IL2046 and IL3051 warnings, so that we don't need to update theISerializerinterface.GitHub Issue (If applicable): closes #
PR Type
What kind of change does this PR introduce?
What is the current behavior?
What is the new behavior?
PR Checklist
Please check if your PR fulfills the following requirements:
Screenshots Compare Test Runresults.Other information
Internal Issue (If applicable):