Skip to content

Unused Symbol Detection

Identify and eliminate dead code with unused symbol highlighting.

Unused symbol detection automatically highlights code that isn’t being used anywhere in your project.

Private methods with no references:

private void UnusedMethod() // Appears grayed out
{
// This method is never called
}

Public and private properties not accessed:

private string UnusedProperty { get; set; } // Grayed out

Fields that are declared but never used:

private int _unusedField; // Grayed out

Events that are never subscribed to or raised:

private event EventHandler UnusedEvent; // Grayed out

Unused symbols appear with reduced opacity (grayed out), making them easy to spot.

  1. Open Settings (Ctrl+,)
  2. Search for csharp-dev-tools.editor.highlightUnusedSymbols
  3. Toggle on/off

Or use Command Palette: “Toggle Unused Symbol Highlighting”

Control how grayed out unused symbols appear:

  1. Search for csharp-dev-tools.editor.unusedSymbolOpacity
  2. Set value between 0.1 (very faint) and 1.0 (normal)

The extension uses:

  1. Primary: C# Language Server diagnostics (IDE0051, etc.)
  2. Fallback: Reference counting for larger files
  3. Scope: File-level detection for performance

Public methods are excluded from detection as they might be:

  • API endpoints
  • Library methods
  • Called from external projects
  • Used via reflection

Methods implementing interfaces are excluded even if not directly called.

Virtual and override methods are excluded as they may be called via polymorphism.

  • Identify methods to remove
  • Find unused properties
  • Eliminate dead code
  • Reduce technical debt
  • Safely remove unused code
  • Simplify classes
  • Improve maintainability
  • Spot accidentally unused code
  • Find leftover experimental code
  • Identify incomplete refactorings
  • Review grayed out code before deleting
  • Check if code is intentionally unused (future use)
  • Consider making unused public methods private
  • Remove truly dead code to reduce complexity

If actively used code appears unused:

  • May be called via reflection
  • Used in other projects/assemblies
  • Called from markup (Blazor, XAML)
  • Toggle off the feature for those files
  • Ensure C# Language Server is running
  • Check file is part of project
  • Verify diagnostic level includes information
  • Rebuild project if needed
  • Lightweight detection
  • Incremental updates
  • Optimized for large files
  • Minimal performance impact