runtime: Why does DisablePrivateReflection attribute not work on .net core 2.1, but works perfectly on .net core 2.0?
Hello!
Why does DisablePrivateReflection attribute not work on .net core 2.1, but works perfectly on .net core 2.0?
I have a class with private fields. The class is in assembly marked with a DisablePrivateReflection attribute.
The following test will be passed successfully on .net core 2.0
var field = typeof(MonLicenseManager).GetField("_licenses", BindingFlags.NonPublic |
BindingFlags.Static);
Assert.IsNotNull(field);
try
{
var value = field.GetValue(null);
Assert.Fail("FieldAccessException must be thrown");
}
catch (FieldAccessException)
{
}
but on .net core 2.1, FieldAccessException will never be thrown
Thanks
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 1
- Comments: 22 (22 by maintainers)
Long story short: please don’t bring it back. Imo, it should’ve never been existed in the first place.
This attribute is interesting for two reasons:
compilercontrolledvisibility (i.e. members are referred to by tokens, not by names where we don’t even have to bother generating short unique names for them). Cc @marek-safar, @vitek-karasIf punted, we will have gone three major releases (2.1, 3.1, 5.0) without this functionality. I don’t really see many people clamoring to bring this back. If we’re unlikely ever to bring it back I’d rather close the issue (and obsolete the type) rather than continue punting.
This was not expected. We should keep respecting the
DisablePrivateReflectionattribute.