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

Polymorphic JSON deserialization hangs indefinitely in native AOT since .NET 9 Preview 7 #108329

Closed
cfbao opened this issue Sep 27, 2024 · 6 comments

Comments

@cfbao
Copy link

cfbao commented Sep 27, 2024

Describe the bug

When used in native AOT apps, System.Text.Json's polymorphic deserialization hangs the program indefinitely.

To Reproduce

Create project with dotnet new console --aot and use the following code:

using System.Text.Json;
using System.Text.Json.Serialization;

Console.WriteLine("start");
var res = JsonSerializer.Deserialize(
	"""
	{
		"$type": "person",
		"Name": "John"
	}
	""",
	MyJsonContext.Default.Base
);

Console.WriteLine($"result: {res}");

[JsonDerivedType(typeof(Person), "person")]
abstract record Base();

record Person(string Name) : Base;

[JsonSerializable(typeof(Base))]
internal partial class MyJsonContext : JsonSerializerContext;

Then publish the app with dotnet publish and start the resulting executable.
The program will hang before printing result: ....

Further technical details

Issue did not exist in .NET SDK 9.0.100-preview.6.24328.19.
Issue started appearing in .NET SDK 9.0.100-preview.7.24407.12 and persists in 9.0.100-rc.1.24452.12.
Issue can be observed on both Windows 10 and WSL2 (Ubuntu 22.04).

@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged New issue has not been triaged by the area owner label Sep 27, 2024
Copy link

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

1 similar comment
Copy link

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

@cfbao
Copy link
Author

cfbao commented Sep 27, 2024

Not sure if this belongs here or in the runtime repo. Please move as you see fit.

@baronfel baronfel transferred this issue from dotnet/sdk Sep 27, 2024
Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-system-text-json, @gregsdennis
See info in area-owners.md if you want to be subscribed.

@eiriktsarpalis
Copy link
Member

Sounds like a potential duplicate of #107740. Are you able to reproduce using the RC2 bits?

@cfbao
Copy link
Author

cfbao commented Sep 27, 2024

Took some fiddling to figure out how to use RC2 but got it working.
I can no longer repro with RC2. Seems like it's resolved then. Great!

@cfbao cfbao closed this as completed Sep 27, 2024
@dotnet-policy-service dotnet-policy-service bot removed the untriaged New issue has not been triaged by the area owner label Sep 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants