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 does not correctly handle nested inner types of a generic outer type. #62762

Closed
333fred opened this issue Dec 14, 2021 · 5 comments · Fixed by #72449
Closed
Labels
area-System.Text.Json bug help wanted [up-for-grabs] Good issue for external contributors
Milestone

Comments

@333fred
Copy link
Member

333fred commented Dec 14, 2021

Description

I'm seeing an ArgumentOutOfRange exception when attempting to use the System.Text.Json source generator in my project. This appears to be when a field or property of a type to be generated is of the form OuterType<T>.Inner.

Reproduction Steps

Attempt to compile the following code:

using System.Text.Json.Serialization;

public class Outer<T>
{
    public class Inner { }
}

public class C
{
    public Outer<int>.Inner I { get; set; }
}

[JsonSerializable(typeof(C))]
public partial class Context : JsonSerializerContext
{
}

Expected behavior

The code compiles.

Actual behavior

CSC : warning CS8785: Generator 'JsonSourceGenerator' failed to generate source. It will not contribute to the output and compilation errors may occur as a result. Exception was of type 'ArgumentOutOfRangeException' with message 'Length cannot be less than zero. (Parameter 'length')' [C:\Users\333fr\Documents\git\omnisharp-roslyn\src\OmniSharp.Abstractions\OmniSharp.Abstractions.csproj]

Followed by errors from lack of partial type implementation.

Regression?

No response

Known Workarounds

No response

Configuration

.NET 6.0.100.

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 Dec 14, 2021
@ghost
Copy link

ghost commented Dec 14, 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'm seeing an ArgumentOutOfRange exception when attempting to use the System.Text.Json source generator in my project. This appears to be when a field or property of a type to be generated is of the form OuterType<T>.Inner.

Reproduction Steps

Attempt to compile the following code:

using System.Text.Json.Serialization;

public class Outer<T>
{
    public class Inner { }
}

public class C
{
    public Outer<int>.Inner I { get; set; }
}

[JsonSerializable(typeof(C))]
public partial class Context : JsonSerializerContext
{
    public static string Implicit => "World";
}

Expected behavior

The code compiles.

Actual behavior

CSC : warning CS8785: Generator 'JsonSourceGenerator' failed to generate source. It will not contribute to the output and compilation errors may occur as a result. Exception was of type 'ArgumentOutOfRangeException' with message 'Length cannot be less than zero. (Parameter 'length')' [C:\Users\333fr\Documents\git\omnisharp-roslyn\src\OmniSharp.Abstractions\OmniSharp.Abstractions.csproj]

Followed by errors from lack of partial type implementation.

Regression?

No response

Known Workarounds

No response

Configuration

.NET 6.0.100.

Other information

No response

Author: 333fred
Assignees: -
Labels:

area-System.Text.Json, untriaged

Milestone: -

@layomia
Copy link
Contributor

layomia commented Dec 20, 2021

This is a bug with correctly generating the full name of some generic types. The full name is used as part of generator's infrastructure for processing serializable types. This bug should be fixed and considered for 6.0 since we have no control of input object graphs and it would be difficult to communicate what's working vs not.

@layomia
Copy link
Contributor

layomia commented Mar 30, 2022

The fix for this issue should verify correctness for these scenarios:

We'll target 7.0 for a fix here. A community contribution/fix here is welcome.

@layomia layomia removed their assignment Mar 30, 2022
@layomia layomia added the help wanted [up-for-grabs] Good issue for external contributors label Mar 30, 2022
@eiriktsarpalis
Copy link
Member

Moving to .NET 8 milestone.

@eiriktsarpalis eiriktsarpalis modified the milestones: 7.0.0, 8.0.0 Jul 19, 2022
@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Jul 20, 2022
@krwq
Copy link
Member

krwq commented Jul 20, 2022

This is fixed with #71619

@krwq krwq closed this as completed Jul 20, 2022
@ghost ghost removed the in-pr There is an active PR which will close this issue when it is merged label Jul 22, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Aug 21, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Text.Json bug help wanted [up-for-grabs] Good issue for external contributors
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants