Skip to main content

How to Resolve Warning "CS0618: 'member' is obsolete: 'text'" in C#

The Compiler Warning CS0618 is a specific deprecation warning. The message reads: "'Member' is obsolete: 'Specific Message'".

This warning is very similar to CS0612, but with one crucial difference: the author of the deprecated code has provided a custom message explaining why the code is obsolete or what you should use instead. This makes CS0618 one of the most helpful warnings in the C# compiler, as the solution is often embedded directly in the error message itself.

This guide explains how to read these deprecation messages and how to handle them properly.

Understanding the Custom Message

When a developer marks code as obsolete, they can use the [Obsolete] attribute in two ways:

  1. [Obsolete] -> Triggers CS0612 (Generic warning).
  2. [Obsolete("Use method B instead")] -> Triggers CS0618 (Warning with instructions).

The text string passed into the attribute is what appears in your Error List. It serves as a direct communication channel from the library author to you.

Scenario: Using a Method Marked with a Message

Suppose you are using a cryptography library or a helper class, and the author has decided that ComputeHash is unsafe and should be replaced.

Definition

public class CryptoHelper
{
// The author provides specific instructions in the string
[Obsolete("ComputeHash is insecure. Please use ComputeSHA256 instead.")]
public void ComputeHash(string data)
{
Console.WriteLine("Computing legacy hash...");
}

public void ComputeSHA256(string data)
{
Console.WriteLine("Computing secure hash...");
}
}

Usage with Warning

public class Program
{
static void Main()
{
var crypto = new CryptoHelper();

// ⛔️ Warning CS0618: 'CryptoHelper.ComputeHash(string)' is obsolete:
// 'ComputeHash is insecure. Please use ComputeSHA256 instead.'
crypto.ComputeHash("secret");
}
}

The primary way to fix CS0618 is to read the string provided in the warning ("...Please use ComputeSHA256 instead") and update your code accordingly.

public class Program
{
static void Main()
{
var crypto = new CryptoHelper();

// ✅ Correct: Using the modern replacement suggested by the warning text.
crypto.ComputeSHA256("secret");
}
}
tip

Always check the IntelliSense tooltip when typing a method name. If it is crossed out (MethodName), hovering over it will display the CS0618 message before you even compile.

Solution 2: Suppress the Warning

If you are maintaining a legacy application and cannot switch to the new method yet (perhaps due to backward compatibility requirements), you can suppress the warning locally.

Using Pragma

Wrap the specific line of code to silence the warning just for that instance.

public class Program
{
static void Main()
{
var crypto = new CryptoHelper();

// ✅ Correct: Warning suppressed.
// We acknowledge the risk but need the old behavior for now.
#pragma warning disable CS0618
crypto.ComputeHash("secret");
#pragma warning restore CS0618
}
}
warning

The "True" Flag: If the author marked the attribute as [Obsolete("Message", true)], this becomes Error CS0619. In that case, the compiler treats it as a hard error, and #pragma suppression will not work. You strictly must update the code.

Conclusion

CS0618 is a friendly warning that includes the solution instructions.

  1. Read the Message: The text after "is obsolete:" tells you exactly what to do.
  2. Refactor: Switch to the recommended replacement method or property.
  3. Suppress: Use #pragma warning disable CS0618 only if you are forced to use legacy code.