runtime
runtime copied to clipboard
Mono: NullabilityInfo.ReadState returns incorrect NullabilityState value
Issue Description
The NullabilityState of NullabilityInfoContext created with a FieldInfo of an Array type field is Unknown in Mono when it is supposed to be NotNull in comparison with CoreCLR.
Test Code
using System.Reflection;
public class Target {
public string?[] ArrayField;
}
public class Samples
{
static public void Test()
{
var type = typeof(Target);
var arrayField = type.GetField("ArrayField");
new NullabilityInfoContext();
var context = new NullabilityInfoContext();
var arrayInfo = context.Create(arrayField);
Console.WriteLine(arrayInfo.ReadState);
}
static void Main(string[] args)
{
Test();
}
}
Expected Behaviour
According to Behaviour in CoreCLR, the NullabilityState of NullabilityInfoContext created with a FieldInfo of an Array type field is NotNull
Environment Information
- Runtime: Seen with 8, 9 and 10
- Platform: Linux
- Comparison environment: CoreCLR (works correctly)
Tagging subscribers to this area: @dotnet/area-system-reflection See info in area-owners.md if you want to be subscribed.
@uweigand @giritrivedi @saitama951