🛠️ Visual Studio: Fix CodeLens Reference Counts Staying at Zero for an Entire Solution Because the Local CodeIndex Cache Under %LocalAppData% Never Finished Its Initial Build
CodeLens relies on a background indexing service that builds and caches the solution’s full symbol-reference graph the first time a solution opens, storing that cache under the hidden .vs folder and under %LocalAppData%. On a large solution opened right after upgrading Visual Studio or an extension, the initial build of that cache can get interrupted — closing Visual Studio, the machine sleeping, a crash — leaving behind a half-built cache that CodeLens then trusts indefinitely instead of ever retrying on its own.
🔎 The Problem
CodeLens references above a method, large solution right after upgrading VS: 0 references | 0 callers <- every method in the solution, always zero Same solution, cache folder deleted and reopened (full reindex forced): 14 references | 3 callers <- real numbers return once indexing completes
✅ Fix: Force a Clean Reindex and Let It Finish
- Close Visual Studio, delete the solution’s hidden
.vsCodeLens cache subfolder (or the whole.vsfolder) along with the global cache under%LocalAppData%\Microsoft\VisualStudio\<version>\ComponentModelCache, then reopen the solution so indexing starts completely fresh instead of resuming from a half-built cache. - Watch the status bar and the Output window’s CodeLens pane during the first reopen and let that initial indexing pass finish completely before touching any file — closing Visual Studio or sleeping the machine mid-index is exactly what leaves the cache in this half-built state the next time.
- For a genuinely large solution, disable CodeLens indicators you don’t rely on (Tools > Options > CodeLens) so the remaining indexers have less to build and are less likely to be interrupted before finishing.
🚨 Why This Is Dangerous
Trusting a “0 references” result can make you delete a method, property or event you believe is unused, only to discover at runtime that it’s called from reflection, a different project, or code the broken index simply never finished scanning.
CodeLens’s numbers are only as fresh as its last completed index — a stale, half-built cache reports confident zeros instead of admitting it never finished counting.
