6

Renaming fails, but only in one of my solutions.

Every time I try to rename a variable/function it prompts for the name change and then fails with the following error:

No references were found in the selected scope. The selected scope is the entire solution so I suspect something is wrong.

I found the following post: https://social.msdn.microsoft.com/Forums/vstudio/en-US/37deb1a5-daa5-47c7-ab50-ed8e57bcf111/rename-class-does-not-work-no-references-were-found-in-the-selected-scope?forum=visualstudiogeneral

But I am concerned that resetting the settings will erase my current settings for each project. I just don't understand why renaming fails only one of the 4 solutions I am working on.

unixsnob
  • 1,685
  • 2
  • 19
  • 45
  • Can you confirm if files are not readonly, some version control systems add a read-only attribute for files. – abhilash Feb 26 '16 at 14:27
  • @ABKolan some of them were marked read-only. However, un-marking them does not let me rename... Any other ideas? – unixsnob Feb 26 '16 at 15:45
  • Dunno if this will help, but I was facing a similar issue with the "No references were found in the selected scope", I realized that I had an extra (old) copy of one of my .cpp files open when I tried to restart visual studio. I got rid of this extra file, restarted visual studio, and it worked. – aquirdturtle Mar 20 '16 at 18:07
  • @Dunno: Unfortunately that is not the case. However, I think it's something related to importing files into the project. I copied them and then I dropped them in. I think that has sort of changed their scope. I managed to get it to work by extending the scope to including external items. No idea why it thinks they are external though... – unixsnob Mar 20 '16 at 18:25

3 Answers3

5

Extending the scope as you and others have suggested will only work in those cases when VS is actually recognizing your references. If "Find All References" (in whatever scope you prefer) works then renaming will also work (if you choose the correct scope).

But many times (happens to me frequently) this is a bug in VS, and unfortunately it's one that's still persisting even today with Visual Studio (Community) 2022 v17.0.5. It can present itself in weird ways, e.g. you can rename some things, but only one time. Other times you can't even rename a single local variable that only appear in two consecutively lines.

More info can be found from this question, and I'll quote the only solution that ever works for me when VS fails to keep track of the references:

  1. Close out of all instances of visual studio
  2. Locate the .vs hidden folder within your solution.
  3. Delete the entire hidden .vs folder.
  4. Rebuild the solution
joakie
  • 144
  • 2
  • 6
2

As I mentioned above, the solution is to extend the scope. I am not sure why the scope does need to be extended though. The files are located inside the project and are part of the version control scope for this project.

unixsnob
  • 1,685
  • 2
  • 19
  • 45
  • 2
    Made it work by switching from "Current Solution" to "Current Project". Makes no sense either - isn't the project part of the solution? – JPNotADragon May 03 '21 at 10:06
  • I'm also noticing this. It seems like someone mixed up the term "project" and "solution" when setting the strings for this feature, because when I'm in my unit testing project and set the scope to "project", it includes references for, e.g., the class being tested (which is in another project in this solution). Although... that doesn't explain why it finds NOTHING when the scope is set to "solution" or even "solution (including external references)" – Twisted on STRIKE at1687989253 Dec 12 '21 at 22:21
  • ...or maybe not. When I actually applied the refactor, it only changed the current project's references. it didn't change the class declaration or anything. still, one has to wonder why it has so much trouble finding exactly the references it checks as part of its static analysis... – Twisted on STRIKE at1687989253 Dec 12 '21 at 22:35
0

I got same problem. but when I change Search scope: Entire Solution (including External Items), It works good.

baljang
  • 11