> ## Documentation Index
> Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
> Use this file to discover all available pages before exploring further.

# C# Obsolete Attribute

The `System.ObsoleteAttribute` is a predefined metadata attribute used to mark program elements that are deprecated. When the C# compiler encounters code that references an element decorated with this attribute, it evaluates the attribute's parameters to emit either a compiler warning or a hard compiler error, effectively altering the compilation state of the referencing code (the caller).

## Syntax and Constructors

The attribute can be applied using three primary constructor overloads, which dictate the severity and messaging of the compiler output.

```csharp theme={"dark"}
// 1. Parameterless: Emits a default compiler warning (CS0612)
[Obsolete]
public class LegacyClass { }

// 2. Message parameter: Emits a warning with a custom message (CS0618)
[Obsolete("This method is deprecated. Call ModernMethod() instead.")]
public void DeprecatedMethod() { }

// 3. Message and Error parameters: Emits a compiler error (CS0619)
[Obsolete("This property is no longer supported.", error: true)]
public string UnsupportedProperty { get; set; }
```

## Parameter Breakdown

* **`message` (`string`)**: A text string injected into the compiler output. It is technically optional but highly recommended to provide redirection to alternative APIs.
* **`error` (`bool`)**: A boolean flag determining the compilation behavior.
  * If `false` (default), the compiler emits a warning (CS0618) and compilation continues.
  * If `true`, the compiler emits an error (CS0619) and halts the build process.
* **`DiagnosticId` (`string`)**: Introduced in .NET 5 (C# 9), this named parameter allows you to assign a custom diagnostic ID to the obsolescence warning. This enables consumers to suppress specific deprecation warnings using `#pragma warning disable <DiagnosticId>` without suppressing all `CS0618` warnings globally.
* **`UrlFormat` (`string`)**: Introduced in .NET 5 (C# 9), this named parameter specifies a URL format string that the compiler uses to generate a clickable link in the IDE pointing to external documentation regarding the deprecation. The format string can optionally include a `{0}` placeholder. If the placeholder is omitted, the compiler treats the provided string as a static URL. If the `{0}` placeholder is included, the compiler replaces it with the value of the `DiagnosticId` property. If `DiagnosticId` is *not* explicitly set, the compiler replaces `{0}` with the default warning code (e.g., `CS0618`).

**Modern Syntax Example (.NET 5+):**

```csharp theme={"dark"}
// Using a format string with a placeholder and a custom DiagnosticId
[Obsolete("Use NewMethod instead.", DiagnosticId = "CONTOSO001", UrlFormat = "https://contoso.com/obsoletions/{0}")]
public void OldMethod() { }

// Using a static URL without a placeholder
[Obsolete("Use AnotherMethod instead.", UrlFormat = "https://contoso.com/obsoletions/another-method")]
public void AnotherOldMethod() { }
```

## Attribute Targets

The `[Obsolete]` attribute is defined using a specific bitwise combination of `AttributeTargets`, specifically: `Class | Struct | Enum | Constructor | Method | Property | Field | Event | Interface | Delegate`.

Because it is restricted to these explicit targets, it cannot be applied to assemblies, modules, parameters, return values, or generic parameters.

## Compiler Resolution Behavior

When the compiler resolves a symbol marked with `[Obsolete]`, it checks the context of the caller. If the calling member is *also* marked as `[Obsolete]`, the compiler suppresses the warning or error. This cascading behavior allows deprecated members to safely reference other deprecated members internally without generating redundant compiler noise.

<div
  style={{ 
display: "flex", 
justifyContent: "space-between", 
alignItems: "center", 
maxWidth: "754px", 
padding: "1rem 0",
marginBottom: "24px"
}}
>
  <span style={{ fontWeight: "bold", fontSize: "1.25rem", color: "var(--tw-prose-headings)", fontFamily: "Inter, ui-sans-serif, system-ui, sans-serif" }}>Tired of Poor C# Skills? Fix That With Deep Grasping!</span>

  <a
    href="https://syntblaze.com"
    target="_blank"
    style={{ 
  marginLeft: "24px",
  textDecoration: "none", 
  backgroundColor: "#007AFF",
  color: "#ffffff", 
  padding: "6px 16px", 
  borderRadius: "16px",
  fontSize: "0.9rem",
  fontWeight: "600",
  textAlign: "center",
  transition: "background-color 0.2s ease"
}}
  >
    Learn More
  </a>
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/skill-tracking.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=b9b0305c93bb501c9e767b5c76c88835" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/skill-tracking.png" />

  <img src="https://mintcdn.com/syntblazellc/23tyuOzaWS88qFlc/images/nuggets.png?fit=max&auto=format&n=23tyuOzaWS88qFlc&q=85&s=c86c80197299762989e9b882419b2109" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/nuggets.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/bite-sized-exercises.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=a65f9a38c37ff28ab73ed783c53c60e3" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/bite-sized-exercises.png" />
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap", marginTop: "12px" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/mastery-chain.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=748a1763454713e679260fbb95f154a2" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/mastery-chain.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-previews.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=242f61448ff5dd6deaaab2dccc13b507" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-previews.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-explanations.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=cf0fc1c31f9cd0fc26716781be05fbc9" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-explanations.png" />
</div>
