Skip to content

Mono: NullabilityInfo.ReadState returns incorrect NullabilityState value #115295

Closed
@Venkad000

Description

@Venkad000

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions