ObsoleteAttribute Class
.NET Framework Class Library
ObsoleteAttribute Class

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

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)
Visual Basic (Declaration)
<SerializableAttribute> _
<AttributeUsageAttribute(AttributeTargets.Class Or AttributeTargets.Struct Or AttributeTargets.Enum Or AttributeTargets.Constructor Or AttributeTargets.Method Or AttributeTargets.Property Or AttributeTargets.Field Or AttributeTargets.Event Or AttributeTargets.Interface Or AttributeTargets.Delegate, Inherited := False)> _
<ComVisibleAttribute(True)> _
Public NotInheritable Class ObsoleteAttribute _
    Inherits Attribute
Visual Basic (Usage)
Dim instance As ObsoleteAttribute
C#
[SerializableAttribute]
[AttributeUsageAttribute(AttributeTargets.Class|AttributeTargets.Struct|AttributeTargets.Enum|AttributeTargets.Constructor|AttributeTargets.Method|AttributeTargets.Property|AttributeTargets.Field|AttributeTargets.Event|AttributeTargets.Interface|AttributeTargets.Delegate, Inherited = false)]
[ComVisibleAttribute(true)]
public sealed class ObsoleteAttribute : Attribute
Visual C++
[SerializableAttribute]
[AttributeUsageAttribute(AttributeTargets::Class|AttributeTargets::Struct|AttributeTargets::Enum|AttributeTargets::Constructor|AttributeTargets::Method|AttributeTargets::Property|AttributeTargets::Field|AttributeTargets::Event|AttributeTargets::Interface|AttributeTargets::Delegate, Inherited = false)]
[ComVisibleAttribute(true)]
public ref class ObsoleteAttribute sealed : public Attribute
JScript
public final class ObsoleteAttribute extends Attribute

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

For more information about using attributes, see Extending Metadata Using Attributes.

The following example defines a class that contains a method marked with the ObsoleteAttribute. Any code that attempts to call the method will cause the compiler to issue a warning.

Visual Basic
Module Module1

    Sub Main()
        ' The line below causes the compiler to issue a warning:
        ' 'App.SomeDeprecatedMethod()' is obsolete: 'Do not call this method.'
        SomeDeprecatedMethod()

    End Sub
    ' The method below is marked with the ObsoleteAttribute. 
    ' Any code that attempts to call this method will get a warning.
    <Obsolete("Do not call this method.")> Private Sub SomeDeprecatedMethod()

    End Sub
End Module
C#
using System;

public sealed class App {
   static void Main() {      
      // The line below causes the compiler to issue a warning:
      // 'App.SomeDeprecatedMethod()' is obsolete: 'Do not call this method.'
      SomeDeprecatedMethod();
   }

   // The method below is marked with the ObsoleteAttribute. 
   // Any code that attempts to call this method will get a warning.
   [Obsolete("Do not call this method.")]
   private static void SomeDeprecatedMethod() { }
}

Visual C++
using namespace System;


// The method below is marked with the ObsoleteAttribute.
// Any code that attempts to call this method will get a warning.
[Obsolete("Do not call this method.")]
void SomeDeprecatedMethod()
{
}

int main()
{
    // The line below causes the compiler to issue a warning:
    // 'SomeDeprecatedMethod()': marked as obsolete
    // Message: 'Do not call this method.'
    SomeDeprecatedMethod();
}

System..::.Object
  System..::.Attribute
    System..::.ObsoleteAttribute
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC, Xbox 360, Zune

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 3.5, 2.0, 1.0

XNA Framework

Supported in: 3.0, 2.0, 1.0
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Missing VB Example      Gary.Pronych   |   Edit   |   Show History
The VB syntax for the Obsolete method is below.


<Obsolete("Do not call this method.")> _
private Sub SomeDeprecatedMethod()

End Sub

Be sure to include the line continuation at the end of the attribute line as shown.

Gary Pronych
Tags What's this?: Add a tag
Flag as ContentBug
Processing
Page view tracker