CodeLens stopped working for some reason in project solution that I'm dealing nowadays. It is not showing references instead "- references". However, when I open up Visual Studio with another project It works like charm.I can confirm that CodeLens is enabled. Do you have any idea to make it work?
CodeLens not showing references
106.1k views Asked by kkocabiyik AtThere are 22 answers
For me, CodeLens was disabled, so make sure it is still enabled.
I know it is an easy answer, but it might help some developers.
Go to Tools -> Options -> Text Editor -> All Languages -> CodeLens then click the "Enable CodeLens" option if it is not checked and then save it.
It looks like VS disabled it for some reason, maybe after an update or slow startup.
I have Visual Studio 2017 Professional on Windows 10. I have observed this under several circumstances:
- MicroSoft decided I needed some critical update for Windows and it installed while I was working - causing some of the VS components to crash.
- Visual Studio update was received in background.
- Some component of Visual Studio crashed - not the VS just some attached feature (did not note exactly which one)
- No known cause.
In each of these cases I did in order (sometimes it worked after each of these)
- Build / Rebuild solution
- Build / Clean Solution
- Close and Restart Visual Studio
- Remove Symbols cache, restart VS
- Close BOTH VS and SSMS and restart them
- Close VS and Restart Windows
- Close VS, force all pending Windows updates to load, restart Windows
- In options, Uncheck Codelens/apply and re-check/apply (OK button)
My Solution:
Toggle the CodeLens feature off and then on again.
Note: Many have found the feature to be turned off after an update so you just need to turn it back on. Thanks to @razblack for calling this out. Don't forget to give his comment an upvote if this was your issue!
- Go into Tools -> Options... -> Text Editor -> All Languages -> CodeLens.
- Uncheck "Enable CodeLens" option and click OK.
- Go back into Tools -> Options... -> Text Editor -> All Languages -> CodeLens.
- Check the "Enable CodeLens" option and click OK.
Note: I've fixed the issue once before by closing the problem .cs file and then reopening it. Closing any referenced files may also be required.
My Problem(s):
Similar to the original poster, CodeLens stopped refreshing references after I made a bunch of refactors. I was seeing stale references to code that didn't exist and I was also seeing the "- references" issue as described in the original post.
My Environment & Specific Scenario:
- Visual Studio 2015 with Service Pack 2 and Resharper Ultimate 10.0.1
- I was doing a major overhaul with a ton of refactoring and my project wasn't compilable for an hour or so. Once I could compile the project again, the references weren't working.
I had the same problem, but one's of my colleagues who has the same development environment than me, doesn't have it...
The only one difference between our both environment was the quantity of RAM. There is 10GB allocated to his VM, and on mine, there is 6GB allocated. Since I upgraded the quantity of RAM allocated to my VM to 8GB, all my references are shown !
I found out that if you block the Visual Studio with the Firewall, the Code Lens did not work.
So unblock it from the firewall to make it work.
Or edit Firewall settings for file:
C:\Windows\Microsoft.NET\assembly\GAC_32\
Microsoft.Alm.Shared.Remoting.RemoteContainer\
v4.0_12.0.0.0__b03f5f7f11d50a3a\
Microsoft.Alm.Shared.Remoting.RemoteContainer.dll
After reading the answer to this Stack Overflow question CodeLens only showing references? I decided my problem with Codelens was I was running Visual Studio 2015 Update 1 but was using Team Foundation Server 2012. I upgraded to TFS 2015, which upgraded in place and didn't require any new settings or URIs to be connected to Visual Studio as before. Then I reloaded my solution - but I still had the issue where it just said "– references" everywhere. I closed Visual Studio, started it again and reloaded my solution and finally I saw the correct reference counts as they used to show.
I had this problem with VS2015 that already had "update 1" installed. The thing was that I originally installed VS2015 with the "custom" setup, not the "default" option, and I accidentally left out the "Git for Windows (3rd party)" option under "Common Tools".
This can be fixed by these steps:
- Run the VS2015 setup again (from control panel - uninstall program)
- Right click VS2015, select "Change"
- On popup screen, select "Modify"
- On setup screen, select "Git for Windows (3rd party)"
- Move on with the setup, install selected features
Just had this problem with VS 2019.
I tried disabling / enabling codelens and it didn't work.
I deleted the .suo after that and it didn't work.
I tried disabling / enabling codelens again (after deleting the .suo) and now it works again.
UPDATE (about 2 weeks later):
It started happening again and this time I disabled IntelliCode in Extensions and all of a sudden Codelens started working again.
UPDATE AGAIN (25 Nov 2019):
I reported this to Microsoft and had a dialog with them. You do not have to turn off all of Intellicode at this time, only disable Intellicode Refactorings in Tools -> Options -> Intellicode. The actual fix is slated for VS 2019 16.4 I believe.
Explicitly enable CodeLens in the workspace settings.json
:
// show code lens on editor
"editor.codeLens": true,
Verify that the following properties show on the editor:
// inline count of reference for classes, interfaces, methods, properties,
// and exported objects
"typescript.referencesCodeLens.enabled": true
I could fix my problem with C# CodeLens and Omnisharp.
My C# extension was 1.25.0. What I did to fix my problem: C# extension -> Unistall -> Install another version -> Version 1.24.4 After that in the settings I searched for "omnisharp: use global mono" and set it from "auto" to "alwayse". Then restart Omnisharp and wait for it to compile and show references.
Same problem here.
CodeLens works normally with small solutions, but not working with large ones.
And this behavior is accompanied with crash of Alm.Shared.Remoting.RemoteContainer.dll process.
Tried in VS 2013 Update 4 and VS 2013 Update 5 RC.
Solution:
Close all programs and clean %LocalAppData%\Temp folder (or maybe just ALM folder inside it).
i was missing the method references ( - references ) codelens settings, removing GitExtensions or visual studio copilot, nothing worked.
i've tried it all, at the end, the only thing that worked like a charm was: Update + Repair
open Run and run the VS tool at:
C:\Program Files (x86)\Microsoft Visual Studio\Installer\setup.exe
update, then repair, if you want to go vanilla, probably overkill, before doing it, restart and delete the temp folder at (using Run):
%temp%
I tried most of the solutions above without luck, as I also saw this problem. On top, certain newly added classes were showing up as white/black (regular text) in Visual Studio.
Changing to Release typically helped, but wasn't a long-term solution. However, this helped on both issues - verified on another machine. Maybe some of the steps can be left out.
- Close all document tabs
- Clean solution
- Right click on solution, click "Enable Lightweight Solution Load"
- Close solution
- Reopen solution
- Right click on solution, click "Disable Lightweight Solution Load"
- Close solution
- Reopen solution
- Rebuild
I found on the new VS 2015 update 3 it happens on a large class in a medium level solution 10+ projects and has nothing to do with circular references, a bad SUO file, or other things. It appears just deleting the temp file location(as mentioned already), closing VS and then reopening and hitting 'ALT+2'(forcing a reference find for Code Lens) made it magically work for me.
It also appears in some solutions and projects Visual Studio will create an old referenced suo file in .vs folder. I don't know the exact rhyme or reason, but it could be created in my case and the CodeLens worked again. It could potentially be a Visual Studio options is somehow referenced in projects under source control. As I know this happened with an older solution I have upgraded many times that was under GitHub control and it does have an .gitignore file(ignore files could change depending on source control). Suffice to say I have had similar things happen with other techs in the past when there is a lock on a source control file that should be updated and won't update. Simple answer is to add to an ignore and delete the settings file.
My Problem Always directly after enabling CodeLens, press OK, i see the extra space required for the CodeLens information and than it disappears and when i look at the options again it is diabled. Driving me nuts.
Approaches Deleting caches/configurations. Clean start without Extensions work. Normal start without ReSharper works. Reinstall ReSharper + deleting cahces -> False behavior
Solution Unter Extensions - ReSharper - Options - Environment - Performance Guide was "Disable CodeLens for all languages" set to "Fix Silently". Set to Ignore -> WORKS!
hope this helps someone
You may have circular references in your solution that prevents CodeLens from working. Some details were provided in the comments for this issue on the Visual Studio Connect site: