Find Dead Code
find_dead_codeDetect unused C# types with no incoming references and private methods with no callers, skipping framework-invoked code, to identify removal candidates.
Instructions
List dead-code suspects on two axes. kinds='type': types with no incoming reference in the reverse type fan-in, the source find_usages reads. kinds='method' (the default): PRIVATE methods whose recorded caller list is empty. kinds='all': both.
The default axis skips a private method a framework may call ([RelayCommand] or other framework attributes, partial methods, markup or designer event handlers, static Main, record PrintMembers, ShouldSerialize/Reset) or whose callers were not measured (unresolved references, explicit interface implementations). A nameof in a method's attribute (CanExecute) is a call. *.Designer.cs and *.g.cs files are read for references, never judged.
Returns scope, a 'note' first when there is one, methodsScanned, deadMethods and - when the type axis ran - typesScanned and deadTypes: at most 200 items each (methods: name, declaringType, namespace; types: name, kind, accessibility, namespace). Counters, each omitted at zero: what was not judged - methodsIneligible (split into methodsIneligibleNotPrivate, methodsIneligibleFrameworkInvoked and methodsIneligibleUnanalyzedCallers), typesIneligible (split into typesIneligibleStructural, typesIneligibleTestScaffolding, typesIneligibleFrameworkActivated, typesIneligibleMarkupReferenced), typesUnexamined (types the type axis would have judged had it run) - and the candidates the test filter removed, testMethodsFiltered and testTypesFiltered.
A listed candidate is a suspect: the note names what a zero fan-in does not prove and how to confirm one. The type axis exempts what it cannot see being used: interfaces, static classes, types named *Extensions, test scaffolding, framework- or reflection-activated types and markup-referenced types. An empty answer without a note means at least one axis judged an eligible population and found nothing; for the method axis read methodsIneligible against methodsScanned.
Read-only; works on a recalled session. Test projects are excluded by default. Any other non-blank kinds value runs both axes.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| kinds | No | 'method' (default): private methods with a measured, empty caller list - see the description for what that axis does not judge; 'type': types with no incoming reference; 'all': both. | method |
| scope | No | 'solution' (default) or a namespace prefix (e.g. 'MyApp.Core') to narrow scope. | solution |
| sessionId | Yes | The session_id returned by analyze_solution. Also takes an absolute .sln/.slnx/.slnf path, analyzed on first use. | |
| includeTests | No | Include test-project methods/types (default false - production dead-code; a private test-helper without callers is not production dead code). |