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

[System.Text.Json] Null ref when attempting to deserialize an json object as an array #31192

Closed
pranavkm opened this issue Oct 16, 2019 · 4 comments · Fixed by dotnet/corefx#42066
Assignees
Milestone

Comments

@pranavkm
Copy link
Contributor

Ran in to this by accident. Not entirely sure if it's already fixed \ tracked since there's a few that are pretty similar to this one:

using System.Text.Json;

namespace ConsoleApp3
{
    class Program
    {
        static void Main(string[] args)
        {
            var json = JsonSerializer.Deserialize<int[]>("{ \"a\": \"b\" }");
        }
    }
}
Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object.
   at System.Text.Json.JsonClassInfo.GetProperty(ReadOnlySpan`1 propertyName, ReadStackFrame& frame)
   at System.Text.Json.JsonSerializer.HandlePropertyName(JsonSerializerOptions options, Utf8JsonReader& reader, ReadStack& state)
   at System.Text.Json.JsonSerializer.ReadCore(JsonSerializerOptions options, Utf8JsonReader& reader, ReadStack& readStack)
   at System.Text.Json.JsonSerializer.ReadCore(Type returnType, JsonSerializerOptions options, Utf8JsonReader& reader)
   at System.Text.Json.JsonSerializer.ParseCore(String json, Type returnType, JsonSerializerOptions options)
   at System.Text.Json.JsonSerializer.Deserialize[TValue](String json, JsonSerializerOptions options)
@layomia layomia self-assigned this Oct 18, 2019
@layomia
Copy link
Contributor

layomia commented Oct 18, 2019

Was able to repro this. @steveharter, @ahsonkhan looks like 3.1 bug?

@ahsonkhan
Copy link
Member

looks like 3.1 bug?

Yes.

It looks like there's a class of null refs that happen whenever the T we are deserializing to doesn't match the input payload. We should look at the previous fixes for similar cases and make sure we are guarding against the whole set.

@ahsonkhan
Copy link
Member

Re-opening until its fixed for 3.1 or we update the milestone.

@ahsonkhan ahsonkhan reopened this Oct 24, 2019
@ahsonkhan
Copy link
Member

Fixed in dotnet/corefx#42071, for 3.1.

@msftgits msftgits transferred this issue from dotnet/corefx Feb 1, 2020
@msftgits msftgits added this to the 3.1 milestone Feb 1, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 12, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
4 participants