diff --git a/docs/csharp/misc/cs0809.md b/docs/csharp/misc/cs0809.md index e2c10d0f872f5..4d2530bcb074f 100644 --- a/docs/csharp/misc/cs0809.md +++ b/docs/csharp/misc/cs0809.md @@ -36,3 +36,37 @@ public class C : Base } } ``` + +## Methods recognized as obsolete + +Note that the compiler warning `CS0809` will lead to no [`CS0618`](../language-reference/compiler-messages/cs0618.md) 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`: + +```csharp +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. + +## See also + +- [CS0618](../language-reference/compiler-messages/cs0618.md) +- [CS0672](./cs0672.md)