#102739 (comment)
var array = new int[] { 1, 2, 3, 4, 5 }; // Uses RVA field for initialization
foreach (var type in typeof(Program).Assembly.GetTypes())
{
if (type.Name.Contains("PrivateImplementationDetails"))
{
foreach (var field in type.GetFields(System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic))
{
_ = field.GetValue(null);
_ = field.GetValue(null);
}
}
}
Currently, the first call is correctly handled by the slow path. Subsequent calls are handled by FieldAccessor and failing. The problems are:
RuntimeFieldHandle.GetStaticFieldAddress is returning the RVA offset, not its address. Trying to access it will cause access violation, and translated to NullReferenceException because it's typically at page 0.
- The managed side of
FieldAccessor tries to read the field as boxed. RVA fields are not boxed.
Test is added in #102739. I'm already working on the fix.
#102739 (comment)
Currently, the first call is correctly handled by the slow path. Subsequent calls are handled by FieldAccessor and failing. The problems are:
RuntimeFieldHandle.GetStaticFieldAddressis returning the RVA offset, not its address. Trying to access it will cause access violation, and translated toNullReferenceExceptionbecause it's typically at page 0.FieldAccessortries to read the field as boxed. RVA fields are not boxed.Test is added in #102739. I'm already working on the fix.