-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Avoid confusion in Reflection with hidden members. #118709
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR addresses a CoreCLR reflection issue where hidden private/internal members in derived classes can make public members in base classes inaccessible through reflection APIs. The fix removes duplicate filtering logic that was incorrectly filtering out legitimate public members when a derived class uses the new
keyword to hide them.
- Removes duplicate property filtering logic in CoreCLR's RuntimeType class
- Adds comprehensive tests for both property and method reflection scenarios with hidden members
- Ensures public base class members remain accessible via reflection even when hidden by derived class members
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
File | Description |
---|---|
src/coreclr/System.Private.CoreLib/src/System/RuntimeType.CoreCLR.cs | Removes duplicate filtering logic that prevented access to hidden public properties |
src/libraries/System.Runtime/tests/System.Reflection.Tests/PropertyInfoTests.cs | Adds test cases and test classes to verify hidden public properties remain accessible |
src/libraries/System.Runtime/tests/System.Reflection.Tests/MethodInfoTests.cs | Adds test cases and test classes to verify hidden public methods remain accessible |
Added When you commit this breaking change:
Tagging @dotnet/compat for awareness of the breaking change. |
src/libraries/System.Runtime/tests/System.Reflection.Tests/PropertyInfoTests.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Runtime/tests/System.Reflection.Tests/PropertyInfoTests.cs
Outdated
Show resolved
Hide resolved
This is a narrow change to address a user reported issue on System.Runtime and the common implementation detail, System.RuntimeType.
df89e40
to
005426d
Compare
I'm closing this issue for now. It is going to require additional discussion for fixes to the underlying issue with Reflection. |
On CoreCLR, the Reflection API was preemptively
filtering out members with the same name and signature.
This means that hidden private members in C# using
the new keyword in derived classes can make public
members in base classes inaccessible.
Add tests for properties and methods.
Fixes #28056
Fixes #98533
Fixes #118677