runtime icon indicating copy to clipboard operation
runtime copied to clipboard

Mono: NullabilityInfo.ReadState returns incorrect NullabilityState value

Open Venkad000 opened this issue 1 year ago • 2 comments

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)

Venkad000 avatar May 05 '25 08:05 Venkad000

Tagging subscribers to this area: @dotnet/area-system-reflection See info in area-owners.md if you want to be subscribed.

dotnet-policy-service avatar May 05 '25 08:05 dotnet-policy-service

@uweigand @giritrivedi @saitama951

Venkad000 avatar May 05 '25 09:05 Venkad000