Skip to content

Conversation

@YOU54F
Copy link
Member

@YOU54F YOU54F commented May 23, 2024

When creating our binaries with PublishTrimmed=True, we get the following warning when building.

Using member 'System.Text.Json.JsonSerializer.Deserialize<TValue>(String, 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.

This results in an error at execution time

processing ...
An error occurred: Method 'get_ReferencePath' in type 'NJsonSchema.JsonSchema' from assembly 'NJsonSchema, Version=10.9.0.0, Culture=neutral, PublicKeyToken=c2f9c3bdfae56102' does not have an implementation.

or

Unhandled exception: System.NotSupportedException: Deserialization of types without a parameterless constructor, a singular parameterized constructor, or a parameterized constructor annotated with 'JsonConstructorAttribute' is not supported. Type 'Explore.Cli.Models.PagedSpaces'. Path: $ | LineNumber: 0 | BytePositionInLine: 1.
 ---> System.NotSupportedException: Deserialization of types without a parameterless constructor, a singular parameterized constructor, or a parameterized constructor annotated with 'JsonConstructorAttribute' is not supported. Type 'Explore.Cli.Models.PagedSpaces'.
   --- End of inner exception stack trace ---
   at System.Text.Json.ThrowHelper.ThrowNotSupportedException(ReadStack& , Utf8JsonRead

Depending on the command.

The resolution appears to be setting PublishTrimmed to False

Related issue:- dotnet/runtime#93714

Copy link
Contributor

@frankkilcommins frankkilcommins left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - we'll review smaller binaries into the future

@YOU54F YOU54F merged commit 7504ae8 into main May 23, 2024
@YOU54F YOU54F deleted the fix/bins branch September 26, 2024 14:50
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 this pull request may close these issues.

3 participants