This article is also available on the Microsoft TechNet Wiki.
The Obsolete Attribute marks elements like classes, methods, properties, fields, delegates, and many others within your code as deprecated or obsolete.The attribute is read at compile time and it is used to generate a warning or an error to the developer.
This attribute can help you if you have ever wanted to make sure programmers use newer versions of your methods. It also makes it easier when you are transitioning from older methods to newer ones. Marking an item as obsolete warns users that program elements will be removed in future versions of the code base.
The attribute is found in the System namespace. The Obsolete attribute decorates a program element by putting the word “Obsolete” above it inside square brackets. Since it is an attribute, you can use either Obsolete or ObsoleteAttribute.
You can use it without arguments and in which case it generates a generic compile-time warning. It can also take one or two optional parameters: Message and IsError.
The Message parameter is a string value with the deprecation message. The message should state that the program element is obsolete and, if possible, point them to the new element to be used.
The IsError parameter is a Boolean value that tells the compiler whether to generate an error or not. An error is generated when IsError is true. If it is set to false, or is not included, then only a warning is generated.
The following code sample shows how to decorate methods with the Obsolete attribute:
// Mark Method1 obsolete without a message.
public static string Method1()
return "You have called Method1.";
// Mark Method2 obsolete with a warning message.
[ObsoleteAttribute("This method will soon be deprecated. Use MethodNew instead.")]
public static string Method2()
return "You have called Method2.";
// Mark Method3 obsolete with an error message.
[ObsoleteAttribute("This method has been deprecated. Use MethodNew instead.", true)]
public static string Method3()
return "You have called Method3.";
public static string MethodNew()
return "You have called MethodNew.";
public static void Main()
The messages generated in the Error List appear as:
The two warnings are shown, as is the requested error.