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

Example usage of NullabilityInfoContext fails on preview.7 #57920

Closed
SimonCropp opened this issue Aug 23, 2021 · 4 comments · Fixed by #58036
Closed

Example usage of NullabilityInfoContext fails on preview.7 #57920

SimonCropp opened this issue Aug 23, 2021 · 4 comments · Fixed by #58036
Assignees
Labels
area-System.Reflection bug in-pr There is an active PR which will close this issue when it is merged
Milestone

Comments

@SimonCropp
Copy link
Contributor

  • 6.0.100-preview.7.21379.14
  • Current Window10
  • VS2019 Preview

here dotnet/core#6444 (comment) the following (slightly modified) example is used

class Target
{
    public (string?, object) TupleField;
}

[Fact]
public void Test()
{
    var type = typeof(Target);
    var tupleField = type.GetField("TupleField");

    var context = new NullabilityInfoContext();

    var tupleInfo = context.Create(tupleField);

    Assert.Equal(NullabilityState.NotNull, tupleInfo.ReadState);
    Assert.Equal(NullabilityState.Nullable, tupleInfo.GenericTypeArguments[0].ReadState);
    Assert.Equal(NullabilityState.NotNull, tupleInfo.GenericTypeArguments[1].ReadState);
}

it fails since tupleInfo.GenericTypeArguments is empty.

I am not sure if this is a bug, or if the API has evolved beyond that example.

Paging @buyaa-n since you posted that usage example

@buyaa-n
Copy link
Contributor

buyaa-n commented Aug 23, 2021

@SimonCropp thank you for reporting, you are right, the example is supposed to have a Tuple, not ValueTuple, i have updated the example with:
public Tuple<string?, object> TupleField;

For some reason i thought no need to check generics for value types, but now I think it should work for ValueTuple, i will fix that, CC @jeffhandley @terrajobst

@buyaa-n buyaa-n transferred this issue from dotnet/core Aug 23, 2021
@dotnet-issue-labeler
Copy link

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged New issue has not been triaged by the area owner label Aug 23, 2021
@buyaa-n buyaa-n added bug and removed untriaged New issue has not been triaged by the area owner labels Aug 23, 2021
@buyaa-n buyaa-n added this to the 6.0.0 milestone Aug 23, 2021
@SimonCropp
Copy link
Contributor Author

@buyaa-n BTW i discovered this when i was building https://github.com/SimonCropp/NullabilityInfo which exposes the new api to older net frameworks via a code only package. if u have time i would appreciate any feedback on the approach

@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Aug 24, 2021
@SimonCropp
Copy link
Contributor Author

thanks @buyaa-n

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Reflection bug in-pr There is an active PR which will close this issue when it is merged
Projects
No open projects
Development

Successfully merging a pull request may close this issue.

2 participants