106

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?

1
  • is it only in specific files? or in everything in that solution? Jan 2, 2014 at 19:12

21 Answers 21

107

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.
5
  • 13
    after upgrading to Update 3, I found that CodeLens had been disabled... switching it back on solved the problem for me too. :)
    – razblack
    Jul 1, 2016 at 4:35
  • 1
    Worked on VS 2017 too! +1+
    – kenny
    Oct 26, 2017 at 14:49
  • This did not work for me, but deleting the .suo file worked.
    – gakera
    Dec 6, 2017 at 16:37
  • Aftter last update vs2017 (15.9.2) CodeLens was disabled, thanks. May 18, 2019 at 12:52
  • VS 2022 Preview had it turned off by default. It's working now. Thanks. Oct 28, 2021 at 13:49
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).

5
  • 3
    Just removing contents under ALM folder worked for me. Cleaning all of it out looked a bit scary to me.
    – KarlZ
    Apr 11, 2016 at 19:33
  • 2
    Worked for me in Vs2017, where there were no circular references. Nov 6, 2017 at 15:43
  • Worked for me too! this should really be the top answer. May 1, 2018 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, 2018 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, 2019 at 10:11
16

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

1
  • 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, 2020 at 15:24
15

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.

2
  • 1
    Strange, it got disabled after update to 16.8.0, wonder what else might have broken...smh
    – Jason
    Nov 11, 2020 at 21:11
  • 1
    I didn't event updated VS and it somehow disabled it self... Feb 23, 2021 at 9:28
14

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

5
  • This fixed it for me, using VS Enterprise 2017 15.4.4
    – gakera
    Dec 6, 2017 at 16:37
  • 2
    I just deleted the .vs folder all together and that worked. VS Enterprise 2017 15.7.3
    – CularBytes
    Jul 4, 2018 at 19:21
  • I think this worked for me. I use VS Professional 2017 version 15.8.5 and this did the trick for me. Sep 27, 2018 at 11:01
  • This worked for me, not removing the ALM folder or toggling code lens off and on again. omg lol I just saw this is the second time this has fixed this problem for me.
    – gakera
    Nov 20, 2018 at 14:32
  • This solution worked for me as well in Visual Studio 2019. Nov 7, 2019 at 8:54
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.

5
  • 1
    I have encountered the problem with VS 2019, I deleted the .suo file, then start again VS and it has worked. Dec 26, 2019 at 6: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. Jan 17, 2020 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? Jan 20, 2020 at 16:01
  • Can you share visual studio forum bug item please so that I can also follow? Feb 5, 2020 at 8: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, 2021 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.

3
  • 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 2, 2014 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, 2015 at 23:12
  • Mine solved removing temp
    – Irf
    Nov 8, 2018 at 7: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
2
  • 3
    I believe you, as our company used something called Avecto Defendpoint caused my VS having the same issue.
    – Vincent
    Jun 10, 2016 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, 2016 at 9: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
1
  • Quick note: My colleague got CodeLens fixed on his VS2015 when he installed VS2015 update 2
    – vpalmu
    Apr 6, 2016 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

1

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

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

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

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.

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.

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)
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
1
  • 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) Feb 16, 2018 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
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.

0

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.