Skip to content

Added another case in the switch block to handle the object returned by Mono which differs from the object returned by CoreCLR #115885

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

Merged
merged 4 commits into from
May 26, 2025

Conversation

Venkad000
Copy link
Contributor

@Venkad000 Venkad000 commented May 22, 2025

Fixes #115295 . Added another case in the switch block to handle the object returned by Mono which differs from the object returned by CoreCLR.

When Create(FieldInfo fieldInfo) is called upon an object of NullabilityInfoContext, the function creates a new object of NullabilityAttributeStateParser by calling CreateParser with a List<CustomAttributes> as argument to it. The NullabilityAttributeStateParser has a member private readonly object? _nullableAttributeArgument which is set to attribute.ConstructorArguments[0].Value in the CreateParser function. CoreCLR returns attribute.ConstructorArguments[0].Value as an object of type ReadOnlyCollection<CustomAttributeTypedArgument> whereas Mono returns it as byte[]. Therefore, the type which is reflected in the switch block is never matched against and hence gets the wrong NullabilityState set to it.

…e the object returned by Mono which differs from CoreCLR.
@github-actions github-actions bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label May 22, 2025
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label May 22, 2025
@Venkad000
Copy link
Contributor Author

@AaronRobinsonMSFT
Copy link
Member

@Venkad000 Can you also please add a test for this? Someplace under https://github.com/dotnet/runtime/tree/main/src/libraries/System.Runtime/tests/System.Reflection.Tests would make the most sense.

/cc @ericstj

@AaronRobinsonMSFT AaronRobinsonMSFT added area-VM-reflection-mono Reflection issues specific to MonoVM and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels May 23, 2025
@Venkad000
Copy link
Contributor Author

wouldn't it be better to add it here https://github.com/dotnet/runtime/blob/main/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Reflection/NullabilityInfoContextTests.cs as this specifically deals with tests regarding NullabilityInfoContext?

@AaronRobinsonMSFT
Copy link
Member

wouldn't it be better to add it here https://github.com/dotnet/runtime/blob/main/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Reflection/NullabilityInfoContextTests.cs as this specifically deals with tests regarding NullabilityInfoContext?

Oh yes, much better. Thanks!

Copy link
Member

@AaronRobinsonMSFT AaronRobinsonMSFT left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Venkad000
Copy link
Contributor Author

@AaronRobinsonMSFT Can we merge this?

@AaronRobinsonMSFT
Copy link
Member

/ba-g Unrelated timeout

@AaronRobinsonMSFT AaronRobinsonMSFT merged commit b61c3e8 into dotnet:main May 26, 2025
139 of 141 checks passed
@Venkad000 Venkad000 deleted the nullability_fix branch May 26, 2025 16:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-VM-reflection-mono Reflection issues specific to MonoVM community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Mono: NullabilityInfo.ReadState returns incorrect NullabilityState value
2 participants