-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
JsonSerializer.Serialize overloads accepting JsonSerializerContext
don't support unspeakable types.
#84260
Comments
Tagging subscribers to this area: @dotnet/area-system-text-json, @gregsdennis Issue DetailsDescriptionWhen using the System.Text.Json source generator, attempting to serialize a compiler-generated instance of Reproduction Stepsusing System.Text.Json;
using System.Text.Json.Serialization;
var todos = GetTodosAsync(10);
var json = JsonSerializer.Serialize(GetTodosAsync(10), todos.GetType(), AppJsonSerializerContext.Default);
async IAsyncEnumerable<Todo> GetTodosAsync(int count)
{
for (int i = 0; i < count; i++)
{
await Task.Delay(10);
yield return new Todo { Id = i, Name = $"Todo {i}" };
}
}
class Todo
{
public int Id { get; set; }
public string? Name { get; set; }
}
[JsonSerializable(typeof(IAsyncEnumerable<Todo>))]
internal partial class AppJsonSerializerContext : JsonSerializerContext
{
} Expected behaviorThe result gets serialized. Actual behaviorAn exception is thrown:
Regression?No, but this was expected to work after the recent changes to support unspeakable types in the JSON source generator. Known WorkaroundsNone. ConfigurationSDK version: 8.0.100-preview.3.23178.7 Other informationNo response
|
We think this should be fixed by dotnet/aspnetcore#47548. Is that right @eiriktsarpalis? |
@eerhardt That's correct when it comes to using When it comes to the particular repro, the reason why runtime/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Helpers.cs Lines 42 to 55 in 50c8895
I had wanted to shim these methods over their |
JsonSerializerContext
don't support unspeakable types.
The changes in #84768 reverted support for unspeakable types in overloads that accept explicit |
Description
When using the System.Text.Json source generator, attempting to serialize a compiler-generated instance of
IAsyncEnumerable<T>
throws an exception saying aTypeInfo
could not be found.Reproduction Steps
Expected behavior
The result gets serialized.
Actual behavior
An exception is thrown:
Regression?
No, but this was expected to work after the recent changes to support unspeakable types in the JSON source generator.
Known Workarounds
None.
Configuration
SDK version: 8.0.100-preview.3.23178.7
Runtime version: 8.0.0-preview.3.23174.8
OS: Windows 11 x64 22H2
Other information
No response
The text was updated successfully, but these errors were encountered: