MemberNotNullWhen() attribute won't work with properties in the base class?

Jonathan Wood 11 Reputation points
2021-09-19T17:11:02.09+00:00

I have a method that guarantees a property is not null when the method returns true.

[MemberNotNullWhen(true, "CurrentLine")]
public bool Read()
{
}

This works fine.

But I also have a class that derives from this class, which has a method that calls the Read() method above. That method also guarantees that the same property is not null when the method returns true.

But when I apply the same attribute to the method in the derived class, I get an error.

Warning CS8776 Member 'CurrentLine' cannot be used in this attribute.

There is no information available on this warning. Does anyone know why I can't use this attribute with a property from a base class?

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,245 questions
{count} votes