Making JsonOptions AOT/Trimmer-safe with EnsureJsonTrimmability switch#45886
Making JsonOptions AOT/Trimmer-safe with EnsureJsonTrimmability switch#45886wtgodbe merged 11 commits intodotnet:mainfrom
JsonOptions AOT/Trimmer-safe with EnsureJsonTrimmability switch#45886Conversation
|
This looks good to start, but we should have code that switches based on this setting. |
💯 I was holding this PR until #45405 is merged to have JsonOptions behave based on this switch, but it is taking longer than I expected. |
JsonOptions AOT/Trimmer-safe with EnsureJsonTrimmability switch
|
Please rebase 🙏 There have been some suppressions added to JsonOptions since the changes were made. Should verify that they are no longer needed with this improvement. |
|
With this change, should the warnings be removed from |
Excellent question. IDK, users can now specify the types,needed for |
|
Yes, the warnings should be removed. |
eerhardt
left a comment
There was a problem hiding this comment.
It would be good to get some tests written when Microsoft.AspNetCore.EnsureJsonTrimmability == false. In dotnet/runtime, we use the RemoteExecutor class to run test code with different runtime config options. See https://github.com/dotnet/runtime/blob/df9de14e807b5327977bcd288fac5dfb4a6c6a6b/src/libraries/System.Reflection.Emit.Lightweight/tests/DynamicMethodCtor.cs#L178-L201 for an example.
| /// <param name="request">The request to read from.</param> | ||
| /// <param name="cancellationToken">A <see cref="CancellationToken"/> used to cancel the operation.</param> | ||
| /// <returns>The task object representing the asynchronous operation.</returns> | ||
| [RequiresUnreferencedCode(RequiresUnreferencedCodeMessage)] |
There was a problem hiding this comment.
Why havne't we done this for all methods in this class? For example,
public static async ValueTask<TValue?> ReadFromJsonAsync<TValue>(
this HttpRequest request,
JsonSerializerOptions? options,
CancellationToken cancellationToken = default)There was a problem hiding this comment.
Similar question for HttpResponseJsonExtensions.
There was a problem hiding this comment.
When the user provides a JsonSerializerOptions the TypeInfoResolver could be null, default value, and we cannot call GetTypeInfo dotnet/runtime#80529
| TypeInfoResolver = TrimmingAppContextSwitches.EnsureJsonTrimmability ? null : CreateDefaultTypeResolver() | ||
| }; | ||
|
|
||
| // Use a copy so the defaults are not modified. |
There was a problem hiding this comment.
What's the plan for the suppressions on line 39-44?
There was a problem hiding this comment.
For now, they will suppress in the Microsoft.AspNetCore.Http.Extensions.WarningSuppressions.xml and I will file an issue to start a discussion if we need something similar to runtime (LibraryBuild.xml).
src/Http/Http.Abstractions/src/ProblemDetails/ProblemDetails.cs
Outdated
Show resolved
Hide resolved
src/Shared/ProblemDetails/HttpValidationProblemDetailsJsonConverter.cs
Outdated
Show resolved
Hide resolved
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
Part of dotnet/sdk#29719