Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Latest linker is raising unexpected warnings in System.Text.Json #2122

Closed
eerhardt opened this issue Jun 30, 2021 · 2 comments · Fixed by #2124
Closed

Latest linker is raising unexpected warnings in System.Text.Json #2122

eerhardt opened this issue Jun 30, 2021 · 2 comments · Fixed by #2124

Comments

@eerhardt
Copy link
Member

With change #2108, we are now getting unexpected ILLink warnings in System.Text.Json. This is blocking merging the latest linker into dotnet/runtime (dotnet/runtime#54907):

ILLink: Trim analysis warning IL2026: System.Text.Json.Nodes.JsonArray: Using method 'System.Text.Json.Nodes.JsonNode.CreateDynamicObject(Expression,JsonNode)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. Using JsonNode instances as dynamic types is not compatible with trimming. It can result in non-primitive types being serialized, which may have their members trimmed.
ILLink: Trim analysis warning IL2026: System.Text.Json.Nodes.JsonArray: Using method 'System.Text.Json.Nodes.JsonArray.Add<T>(T)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. 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.
ILLink: Trim analysis warning IL2026: System.Text.Json.Nodes.JsonArray: Using method 'System.Text.Json.Nodes.JsonNode.TrySetMemberMethodInfo.get' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. 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.
ILLink: Trim analysis warning IL2026: System.Text.Json.Serialization.Metadata.JsonTypeInfo: Using method 'System.Text.Json.Serialization.Metadata.JsonTypeInfo.JsonTypeInfo(Type,JsonSerializerOptions)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. 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.
ILLink: Trim analysis warning IL2026: System.Text.Json.Serialization.Metadata.JsonTypeInfo: Using method 'System.Text.Json.Serialization.Metadata.JsonTypeInfo.JsonTypeInfo(Type,JsonConverter,Type,JsonSerializerOptions)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. 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.
ILLink: Trim analysis warning IL2026: System.Text.Json.Nodes.JsonValue`1: Using method 'System.Text.Json.Nodes.JsonValue.Create<T>(T,Nullable<JsonNodeOptions>)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. 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.
ILLink: Trim analysis warning IL2026: System.Text.Json.Nodes.JsonValue`1: Using method 'System.Text.Json.Nodes.JsonNode.CreateDynamicObject(Expression,JsonNode)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. Using JsonNode instances as dynamic types is not compatible with trimming. It can result in non-primitive types being serialized, which may have their members trimmed.
ILLink: Trim analysis warning IL2026: System.Text.Json.Nodes.JsonValue`1: Using method 'System.Text.Json.Nodes.JsonNode.TrySetMemberMethodInfo.get' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. 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.

I reverted 2f62607 locally and verified that without that change we don't get any warnings. So this feels like a bug introduced with that change.

Going through the warnings listed above, all those methods do have [RequiresUnreferencedCode] applied to them, but all calls of the unsafe methods are either suppressed, or the caller has [RequiresUnreferencedCode] itself. So I'm not seeing what is wrong with the library code.

@marek-safar @agocke @sbomer @MichalStrehovsky

@marek-safar
Copy link
Contributor

I think Vitek is away so as to not block the update I think we should temporary revert the change

@sbomer
Copy link
Member

sbomer commented Jun 30, 2021

These warnings are being produced when the linker doesn't understand DebuggerDisplayAttribute (see #1873 ) and keeps everything on the type and its base types, including RUC methods. It looks like the change intentionally makes this a warning: 2f62607#diff-01d5cdba81adac78da3b5bfc7c322f70461fe7bbf59772b62bb130ab07b7213aR692.

For example JsonTypeInfo has [DebuggerDisplay("ConverterStrategy.{ConverterStrategy}, {Type.Name}")]. The linker doesn't understand it, and keeps everything on JsonTypeInfo.

Or for JsonArray, which has [DebuggerDisplay("JsonArray[{List.Count}]")], it keeps methods on JsonArray and the base type JsonNode.

sbomer added a commit to sbomer/linker that referenced this issue Jun 30, 2021
agocke pushed a commit to dotnet/runtime that referenced this issue Nov 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants