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

During Json Serialization of a 2d array, JsonIgnore attribute not being checked before data type support validation #61205

Closed
phumphreys opened this issue Nov 4, 2021 · 4 comments
Labels
area-System.Text.Json untriaged New issue has not been triaged by the area owner

Comments

@phumphreys
Copy link

Description

I updated my machine with .Net (6.0.100-rc.2.21505.57). While testing various parts of my Blazor WebAssembly App, I started getting a System.NotSupportedException from a WebAPI call. An exception was being thrown trying to JsonSerialize a class with a double[,] property that had the [JsonIgnore] attribute.

Reproduction Steps

Here is a minimal API version of an app that exhibits the issue:

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

Sample items = new();

Console.WriteLine($"Serialized = : {JsonSerializer.Serialize(items)}");

public class Sample
{
    [JsonIgnore]
    public double[,] Data { get; set; }
}

Expected behavior

The expectation is that the JsonSerializer would check for a JsonIgnore attribute before performing any other property validation checks.

Actual behavior

The JsonSerializer does not check for a JsonIgnore attribute before determining if the data type is supported.

Regression?

I don't recall which version of .Net6 I had been testing before I updated, but it was more than likely the public version prior to 6.0.100-rc.2.21505.57.

Known Workarounds

The workaround I used, was to drop back to the early days of Getter and Setter methods instead of using a property.

Configuration

.Net
Blazor WebAssembly Application using .Net 6.0.100-rc.2.21505.57

OS Version
Windows 10 Pro x64, Version 21H1, OS build 19043.1237 with Windows Feature Experience Pack 120.2212.3530.

Browser
Microsoft Edge
Version 95.0.1020.40 (Official build) (64-bit)

Editor
Microsoft Visual Studio Community 2022 Preview (64-bit)
Version 17.0.0 Preview 7.0

Other information

No response

@dotnet-issue-labeler dotnet-issue-labeler bot added area-System.Text.Json untriaged New issue has not been triaged by the area owner labels Nov 4, 2021
@ghost
Copy link

ghost commented Nov 4, 2021

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

Issue Details

Description

I updated my machine with .Net (6.0.100-rc.2.21505.57). While testing various parts of my Blazor WebAssembly App, I started getting a System.NotSupportedException from a WebAPI call. An exception was being thrown trying to JsonSerialize a class with a double[,] property that had the [JsonIgnore] attribute.

Reproduction Steps

Here is a minimal API version of an app that exhibits the issue:

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

Sample items = new();

Console.WriteLine($"Serialized = : {JsonSerializer.Serialize(items)}");

public class Sample
{
    [JsonIgnore]
    public double[,] Data { get; set; }
}

Expected behavior

The expectation is that the JsonSerializer would check for a JsonIgnore attribute before performing any other property validation checks.

Actual behavior

The JsonSerializer does not check for a JsonIgnore attribute before determining if the data type is supported.

Regression?

I don't recall which version of .Net6 I had been testing before I updated, but it was more than likely the public version prior to 6.0.100-rc.2.21505.57.

Known Workarounds

The workaround I used, was to drop back to the early days of Getter and Setter methods instead of using a property.

Configuration

.Net
Blazor WebAssembly Application using .Net 6.0.100-rc.2.21505.57

OS Version
Windows 10 Pro x64, Version 21H1, OS build 19043.1237 with Windows Feature Experience Pack 120.2212.3530.

Browser
Microsoft Edge
Version 95.0.1020.40 (Official build) (64-bit)

Editor
Microsoft Visual Studio Community 2022 Preview (64-bit)
Version 17.0.0 Preview 7.0

Other information

No response

Author: phumphreys
Assignees: -
Labels:

area-System.Text.Json, untriaged

Milestone: -

@phumphreys phumphreys changed the title During Json Serialization of a 2d array, JsonIgnoe attribute not being checked before data type support validation During Json Serialization of a 2d array, JsonIgnore attribute not being checked before data type support validation Nov 4, 2021
@eiriktsarpalis
Copy link
Member

eiriktsarpalis commented Nov 4, 2021

I can reproduce the issue with 6.0.100-rc.2.21505.57, but not with the latest release/6.0 bits. I believe this was fixed by #60299 , presumably the fix didn't find its way to RC2? @layomia to confirm.

@ericstj
Copy link
Member

ericstj commented Nov 4, 2021

Correct, the change was only made in GA.
image
12fb2c3 (note absence of 6.0-rc2)
image

You can get the fix if you'd like by pulling the latest System.Text.Json package from https://dev.azure.com/dnceng/public/_packaging?_a=package&feed=dotnet6%40Local&package=System.Text.Json&protocolType=NuGet&version=6.0.0-rtm.21518.12 or wait for the GA release.

@ericstj ericstj closed this as completed Nov 4, 2021
@phumphreys
Copy link
Author

The RTM version looks good. Thank you both for the quick response!

@ghost ghost locked as resolved and limited conversation to collaborators Dec 4, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Text.Json untriaged New issue has not been triaged by the area owner
Projects
None yet
Development

No branches or pull requests

3 participants