Compiler Warning (level 1) CS0809
Obsolete member 'memberA' overrides non-obsolete member 'memberB'.
Typically, a member that is marked as obsolete should not override a member that is not marked as obsolete. This warning is generated in Visual Studio 2008 but not in Visual Studio 2005.
Remove the Obsolete
attribute from the overriding member, or add it to the base class member.
// CS0809.cs
public class Base
{
public virtual void Test1()
{
}
}
public class C : Base
{
[System.Obsolete()]
public override void Test1() // CS0809
{
}
}
Note that the compiler warning CS0809
will lead to no CS0618
warning when actually calling the obsolete method.
In the following example compiler will not warn about the method Test
being obsolete, because the declaration that is recognized by compiler when calling is in the base class Base
, not the derived class Derived
:
class Base
{
public virtual void Test() {}
}
class Derived : Base
{
[System.Obsolete()]
public override void Test() { }
}
static class Program
{
public static void Main()
{
Derived derived = new();
b.Foo(); // No CS0618
}
}
To fix this add the Obsolete
attribute to base class as well.
.NET feedback
.NET is an open source project. Select a link to provide feedback: