Expand
ObsoleteAttribute Class

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

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)
Syntax

'Declaration

<SerializableAttribute> _
<ComVisibleAttribute(True)> _
<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)> _
Public NotInheritable Class ObsoleteAttribute _
	Inherits Attribute
Remarks

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.

Examples

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.


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


Inheritance Hierarchy

System.Object
  System.Attribute
    System.ObsoleteAttribute
Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Platforms

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role not supported), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Version Information

.NET Framework

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

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Community ContentAdd
How to suppress compiler warnings for obsolete members
Compiler warnings about this attribute can be suppressed by surrounding the usage of code decorated with this attribute with pragma 618.
Example:
#pragma warning disable 618
//use obsolete class/method here
#pragma warning restore 618
Page view tracker