Skip to content

CS0809 should mention that the ObsoleteAttribute will not work if applied to an overidden member only #41621

@rhys-vdw

Description

@rhys-vdw

Type of issue

Missing information

Description

Seems that the following will not trigger an obsolete warning.

class A {
  public virtual void Foo() {}
}

class B : A {
  [Obsolete("doesn't work")]
  public override void Foo() {}
}

static class C {
  public static void Test() {
    B b = new();
    b.Foo(); // <-- no warning raised
  }
}

The current docs say:

Typically, a member that is marked as obsolete should not override a member that is not marked as obsolete.

Which suggests this is a code smell or unidiomatic. More relevant (imo) is that the attribute will be ignored by compiler.

In this case I visited the info page to find out whether it would actually be a problem to ignore the warning. I don't fully understand the reasons why it's ignored, but I feel an explanation here would be helpful.

Thanks!

Page URL

https://learn.microsoft.com/en-us/dotnet/csharp/misc/cs0809

Content source URL

https://github.com/dotnet/docs/blob/main/docs/csharp/misc/cs0809.md

Document Version Independent Id

d83911ea-0426-fc82-622a-3c607d7b787a

Article author

@BillWagner

Metadata

  • ID: 315af9fc-a5f1-9a51-a154-a7c703975a91
  • Service: dotnet-csharp
  • Sub-service: errors-warnings

Metadata

Metadata

Labels

dotnet-csharp/svcerrors-warnings/subsvchelp wantedGood for community contributors to help [up-for-grabs]in-prThis issue will be closed (fixed) by an active pull request.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions