-
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
NullReferenceException when deserializing object containing nullable struct using source generator #86483
Comments
Tagging subscribers to this area: @dotnet/area-system-text-json, @gregsdennis Issue DetailsDescriptionCalling Reproduction Steps
A NullReferenceException will be thrown on the Expected behaviorCalling Actual behaviorException Message: Stack Trace:
Regression?Yes. This code worked correctly in .net 8 preview 3 Known WorkaroundsCall Configuration
Other informationNo response
|
It looks like the Nullable converter is not forwarding relevant metadata of the converter it is encapsulating. Minimal reproduction: JsonSerializer.Deserialize<MyStruct?>("""{"Value":42}""");
public readonly struct MyStruct
{
[JsonConstructor]
public MyStruct(int value) => Value = value;
public int Value { get; }
} |
Description
Calling
JsonSerializer.Deserialize
for an object containing a nullable struct property will throw a NullReferenceException when passing JsonTypeInfo.Reproduction Steps
A NullReferenceException will be thrown on the
var result = JsonSerializer.Deserialize(json, SerializerContext.Default.MyObj);
lineExpected behavior
Calling
JsonSerializer.Deserialize
method does not throw NullReferenceExceptionActual behavior
Exception Message:
Object reference not set to an instance of an object.
Stack Trace:
Regression?
Yes. This code worked correctly in .net 8 preview 3
Known Workarounds
Call
var result = JsonSerializer.Deserialize<MyObj>(json);
without using the JsonTypeInfoConfiguration
Which version of .NET is the code running on?
.net 8 preview 4
What OS and version, and what distro if applicable?
Windows 11
What is the architecture (x64, x86, ARM, ARM64)?
x64
Do you know whether it is specific to that configuration?
Not sure
Other information
No response
The text was updated successfully, but these errors were encountered: