-
Notifications
You must be signed in to change notification settings - Fork 10k
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
Making JsonOptions
AOT/Trimmer-safe with EnsureJsonTrimmability switch
#45886
Making JsonOptions
AOT/Trimmer-safe with EnsureJsonTrimmability switch
#45886
Conversation
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
@@ -32,13 +32,14 @@ public static class HttpRequestJsonExtensions | |||
/// <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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar question for HttpResponseJsonExtensions
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When the user provides a JsonSerializerOptions
the TypeInfoResolver
could be null, default value, and we cannot call GetTypeInfo
dotnet/runtime#80529
@@ -26,7 +27,7 @@ public class JsonOptions | |||
// The JsonSerializerOptions.GetTypeInfo method is called directly and needs a defined resolver | |||
// setting the default resolver (reflection-based) but the user can overwrite it directly or calling | |||
// .AddContext<TContext>() | |||
TypeInfoResolver = CreateDefaultTypeResolver() | |||
TypeInfoResolver = TrimmingAppContextSwitches.EnsureJsonTrimmability ? null : CreateDefaultTypeResolver() | |||
}; | |||
|
|||
// Use a copy so the defaults are not modified. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the plan for the suppressions on line 39-44?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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