System.ObsoleteAttribute Class

Marks the program elements that are no longer in use. This class cannot be inherited.

See Also: ObsoleteAttribute Members


[System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Struct | System.AttributeTargets.Enum | System.AttributeTargets.Constructor | System.AttributeTargets.Method | System.AttributeTargets.Property | System.AttributeTargets.Field | System.AttributeTargets.Event | System.AttributeTargets.Interface | System.AttributeTargets.Delegate | System.AttributeTargets.All, Inherited=false)]
public sealed class ObsoleteAttribute : Attribute


ObsoleteAttribute is applicable to all program elements except assemblies, modules, parameters, and return values. Marking an element as obsolete informs users that the element will be removed in future versions of the product.

The ObsoleteAttribute class includes two properties:

For more information about using attributes, see [<topic://cpconExtendingMetadataUsingAttributes>].

win8_appname_long Apps

When you create a Windows Metadata library (.winmd file), the ObsoleteAttribute is exported as both the ObsoleteAttribute attribute and the tp:// attribute if only the ObsoleteAttribute is present in source code. The ObsoleteAttribute is transformed to the DeprecatedAttribute as follows:


Directly applying the tp:// attribute to managed code is not recommended, because this export occurs automatically.

Thread Safety

All public static members of this type are safe for multithreaded operations. No instance members are guaranteed to be thread safe.


The following example demonstrates the usage of ObsoleteAttribute to generate a compile-time warning.

C# Example

using System;

public class ObsoleteAttributeExample {

  [ObsoleteAttribute("OldMethod is being removed: use NewMethod in future versions.")]
  public static void OldMethod() {

    //Execute some code here

  public static void Main() { 


An example compile-time result is

ObsoleteAttributeExample.cs(8,4): warning CS0618: 'ObsoleteAttributeExample.OldMethod()' is obsolete: 'OldMethod is being removed: use NewMethod in future versions.'


Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0,,