110

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?

kkocabiyik
  • 4,246
  • 7
  • 30
  • 40

22 Answers22

114

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.
GrayDwarf
  • 2,469
  • 2
  • 20
  • 22
55

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).

Wolf
  • 121
  • 4
frobo7
  • 567
  • 4
  • 4
  • 3
    Just removing contents under ALM folder worked for me. Cleaning all of it out looked a bit scary to me. – KarlZ Apr 11 '16 at 19:33
  • 2
    Worked for me in **Vs2017**, where there were no circular references. – Binary Worrier Nov 06 '17 at 15:43
  • Worked for me too! this should really be the top answer. – MistaGoustan May 01 '18 at 23:36
  • 6
    I have VS 2017, but for some reason the ALM folder doesn't exist under the above Temp directory :| – Radderz Jun 19 '18 at 12:40
  • 1
    Helped also for VS2019 - for some files of the solution it was ok, for others codelens was totally missing. The issue remained also after VS minor update, deleting .vs folder. Cleaning the Temp folder helped finally. – Sz. Moncz Nov 15 '19 at 10:11
17

A simple solution, which works!

I did try enabling CodeLens in Visual Studio (2015) -->

  1. Quick Launch (Ctrl+Q) Ctrl+Q
  2. Options (CodeLens) CodeLens Options

But, it was enabled :( Then, it did work with: (Closing the programs), Win+R --> %temp% EnterDelete all

nothing but a Win+R

Irf
  • 4,285
  • 3
  • 36
  • 49
  • my solution didn't help me lately.. tried different versions Finally what worked was, made a _fetch_ .. `pull request` from `git`, and _`references`_ started _showing up_ again!! (bit fishy eh ha _!!_ ) – Irf Jun 29 '20 at 15:24
16

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.

Bashir Momen
  • 1,461
  • 19
  • 17
14

Try to remove .suo file which is storing some enviroment/solution settings. This helped me.

Ivan Stelmakh
  • 195
  • 1
  • 6
11

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.

Mike Cheel
  • 12,626
  • 10
  • 72
  • 101
  • 1
    I have encountered the problem with VS 2019, I deleted the .suo file, then start again VS and it has worked. – Pierre-Olivier Pignon Dec 26 '19 at 06:14
  • Yes, I can confirm that disabling Intellicode refactorings made everything work again. I can work normally on .net core 2.2 and 3.1 again. VS2019. – Mário Meyrelles Jan 17 '20 at 11:44
  • 1
    You saved my day! Thanks. Do you have the actual Visual Studio forum bug item so I can follow in order to restore the Intellicode option? – ArchieCoder Jan 20 '20 at 16:01
  • Can you share visual studio forum bug item please so that I can also follow? – Uzair Ashraf Feb 05 '20 at 08:24
  • 1
    I just upgraded to 16.10.4 this morning and Show References was completely removed from the Options window. After disabling Intellicode and restarting, Show References returned and Code Lens again started showing method references. – stricq Jul 21 '21 at 16:30
7

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:

Somehow, two of my projects in my solution ended up referencing each other causing a circular reference. I think it was a by-product of Resharper's shortcut to reference an undefined class. Once I was cleaned up all of the references, I'm now getting valid values in my reference counts.

How did you go about "cleaning" up references?

In my case, my solution has multiple project files. In the references folder of Project A, there was a reference to Project B. In the references folder of Project B, there was a reference to Project A. This was causing the circular reference. If you try to do this "manually", VS will prompt you with a warning regarding the circular reference.

To clean this up, I removed the reference to Project B from my Project A. I had do some minor class definitions in my Project B so everything would still compile in the end.

cgmb
  • 4,284
  • 3
  • 33
  • 60
Eric Johnson
  • 1,377
  • 7
  • 6
  • 2
    I couldn't find the circular dependency however i realized that it starts showing references when i change the build to release configuration :) But yes it seems it is some kinds of circular dependency issue. – kkocabiyik Jan 02 '14 at 19:52
  • 3
    The link seems to be broken, so I grabbed the sections that appeared relevant from the Google webcache and added them directly to the answer. – cgmb Sep 28 '15 at 23:12
  • Mine [solved _removing_ temp](https://stackoverflow.com/questions/20823805/codelens-not-showing-references/53203247#53203247) – Irf Nov 08 '18 at 07:48
4

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
StayOnTarget
  • 11,743
  • 10
  • 52
  • 81
Aristos
  • 66,005
  • 16
  • 114
  • 150
  • 3
    I believe you, as our company used something called Avecto Defendpoint caused my VS having the same issue. – Vincent Jun 10 '16 at 14:44
  • @Vincent What can I say, for me this what the issue, the local firewall - and before find it, I have come to that page that did not help me... – Aristos Jun 11 '16 at 09:11
2

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
vpalmu
  • 524
  • 4
  • 13
  • Quick note: My colleague got CodeLens fixed on his VS2015 when he installed VS2015 update 2 – vpalmu Apr 06 '16 at 20:10
2

In Visual Studio Professional or Enterprise you can enable CodeLens by doing this:

Tools → Options → Text Editor → All Languages → CodeLens->Enable

This is not available in some Community Edition versions

jithu
  • 1,867
  • 1
  • 7
  • 16
1

Try deleting .suo file inside of the hidden .vs folder in your project. This worked for me in VS 2017.

Emulic
  • 173
  • 5
  • 14
1

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

Marco G
  • 102
  • 5
0

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 !

0

Installing Update 1 for Visual Studio 2015 fixed the problem for me.

Download Update 1

martinoss
  • 5,268
  • 2
  • 45
  • 53
0

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.

Community
  • 1
  • 1
StackOverflowUser
  • 945
  • 12
  • 10
0

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.

djangojazz
  • 14,131
  • 10
  • 56
  • 94
0

I have Visual Studio 2017 Professional on Windows 10. I have observed this under several circumstances:

  1. MicroSoft decided I needed some critical update for Windows and it installed while I was working - causing some of the VS components to crash.
  2. Visual Studio update was received in background.
  3. Some component of Visual Studio crashed - not the VS just some attached feature (did not note exactly which one)
  4. 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)
Mark Schultheiss
  • 32,614
  • 12
  • 69
  • 100
0

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
  • My issue seems to be resolved in VS 2017, v15.5.6 - actually, it turned out to be a problem with the solution's .suo file (in the hidden .vs folder under the solution). The problem often appeared after switching branch in Git. Closing the solution, deleting the .suo and opening again solved it. A bit easier that what I suggested above. (But still annoying) – Jimmy B. Carlsen Feb 16 '18 at 11:42
0

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
diogo
  • 525
  • 1
  • 7
  • 12
0

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.

hojjat reyhane
  • 648
  • 1
  • 8
  • 25
0

Removing data from %temp% folder resolved my issue in VS 2022.

GDBxNS
  • 139
  • 6
0

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%

enter image description here

Yakir Manor
  • 4,687
  • 1
  • 32
  • 25