-
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
System.Text.Json source generator doesn't work with native AOT IlcDisableReflection
#68093
Comments
Tagging subscribers to this area: @dotnet/area-system-text-json, @gregsdennis Issue DetailsDescriptionSystem.Text.Json source generator generates code (that calls code) that uses reflection, hence incompatible with the Was expecting that source generator can eliminate reflection and work with offending line seems to be this: runtime/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonConverterOfT.cs Line 22 in 7368836
Reproduction Steps
using System.Text.Json;
using System.Text.Json.Serialization;
MyClass stuff = new() { Prop = "value" };
string json = JsonSerializer.Serialize( stuff, MyJsonContext.Default.MyClass );
Console.WriteLine( json );
internal record MyClass {
public string? Prop { get; set; }
}
[JsonSerializable( typeof( MyClass ) )]
internal partial class MyJsonContext : JsonSerializerContext { }
Expected behaviorprogram prints Actual behaviorthe following error shows up
Regression?No response Known WorkaroundsNo response Configuration.NET SDK 7.0.100-preview.3.22179.4, commit c48f2c30ee Other informationNo response
|
|
I think we can close this as wontfix. Most of the System.Text.Json.Serialization infrastructure depends on some degree of reflection, even in source generated scenaria. We likely won't be able to change this in the future. That being said, fast-path serialization in source gen should not require any reflection in principle, however fast-path deserialization is not yet implemented (#55043) and it is still missing features compared to the metadata-based serializer. |
Description
System.Text.Json source generator generates code (that calls code) that uses reflection, hence incompatible with the
IlcDisableReflection
native AOT option.Was expecting that source generator can eliminate reflection and work with
IlcDisableReflection
.offending line seems to be this:
runtime/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonConverterOfT.cs
Line 22 in 7368836
Reproduction Steps
Program.cs
with the following<IlcDisableReflection>true</IlcDisableReflection>
to csproj filedotnet publish -r <RID>
Expected behavior
program prints
{"Prop":"value"}
on the consoleActual behavior
the following error shows up
Regression?
No response
Known Workarounds
No response
Configuration
.NET SDK 7.0.100-preview.3.22179.4, commit c48f2c30ee
Windows 10.0.18363, RID: win10-x64
Host version: 7.0.0-preview.3.22175.4, commit 162f836
Other information
No response
The text was updated successfully, but these errors were encountered: