65

I suddenly started experiencing a problem today in my project where clicking Go To Definition gives me a strange error: "Cannot navigate to the symbol under the caret."

enter image description here

I first noticed it some time after installing Costura.Fody via NuGet. I've since uninstalled it but the problem persists. I've cleaned and rebuilt the solution multiple times. There are no instances of "Fody" or "Costura" anywhere in my git commit history, before or after the point in time when this started happening, so I'm thinking that one of my .gitignore'd files is stuck in a bad state.

The problem only occurs if the definition being targeted is in another file; Go To Definition for something in the currently opened file works fine. Peek Definition works fine too. Other solutions/projects work fine as well -- it's only this one that's causing issues.

I'm using Visual Studio 2015. The issue doesn't seem to occur in the 2013 version.

Why does this error occur and how can I fix it?

Jeff
  • 7,504
  • 3
  • 25
  • 34
  • 1
    Try to clear the Temp files related to VS 2015 and try it – Krsna Kishore Oct 27 '15 at 04:49
  • 2
    Same problem. **Peek works, Go To does not.** I can use peek and **promote** for two-click solution. WTF. Cache clearing does not help. I even reopened the solution from C: (as I have mapping B: = C:\devel), cleared and rebuilded solution, restarted VS and even PC... nothing helps. – firda Jan 06 '16 at 10:42
  • 1
    Hitting refresh icon in solution explorer while focused on the project solved the problem for me. – Sam-Elie Nov 02 '17 at 09:07

31 Answers31

165

I got the same problem. I did all those steps mentioned in all above comments. It didn't work. But when I closed Visual Studio, deleted ".vs" folder (in the solution folder) then reopened Visual Studio. It now works like a charm. The problem is gone.

Anthony
  • 1,882
  • 2
  • 9
  • 18
77

The last couple of days I've been getting this error, at least twice a day.. really annoying! None of the solutions proposed here has worked for me. What I found, and since it was pretty difficult to find I'm writing it down here, was to:

  • Close Visual
  • Open Console and navigate to Visual installation folder, in my computer is C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE
  • run devenv.exe /resetuserdata
  • Open Visual Studio, it's going to take some time to load.

Disclaimer: I'm using Xamarin

TAKE INTO CONSIDERATION WHAT @OzSolomon and @xCasper HAVE SAID:

@OzSolomon

Know that this will reset many of your IDE customization, including installed plugins.

Make sure you're comfortable with that before using /resetuserdata

@xCasper

If you have your settings synced through Microsoft, however, most of the preferences seem to restore themselves. I say most because it seems my keybindings did not restore and are back to being default. Everything else, such as my selected theme and colorization choices, the layout of my IDE (where I have tabs for instance), and what not seem to of come back.

fabricio
  • 1,385
  • 17
  • 22
  • This is ultimately the solution that worked for me so I'll accept this one; however, as other users have mentioned in other answers, there may indeed be multiple solutions to the problem. – Jeff Sep 27 '16 at 14:48
  • 19
    To anyone considering this: Know that this will reset many of your IDE customization, including installed plugins. Make sure you're comfortable with that before using `/resetuserdata` – Oz Solomon Jan 06 '17 at 21:32
  • 1
    This definitely fixed the issue for me. Please note what @OzSolomon said about it wiping your data. If you have your settings synced through Microsoft, however, most of the preferences seem to restore themselves. I say most because it seems my keybindings did not restore and are back to being default. Everything else, such as my selected theme and colorization choices, the layout of my IDE (where I have tabs for instance), and what not seem to of come back. – xCasper Jan 22 '17 at 09:48
  • 1
    This "Know that this will reset many of your IDE customization, including installed plugins. Make sure you're comfortable with that before using /resetuserdata" should go in bold with "WARNING" title. -1 – Varvara Kalinina Sep 04 '17 at 13:33
  • @VarvaraKalinina I assumed that "Take into consideration..." in bold and all capitals was going to be enough. My bad, gonna change it. – fabricio Sep 04 '17 at 14:44
  • @fabricio I know that you did not mean anything bad, but as many people I don't always finish reading the whole answer on SO. If I saw some kind of ATTENTION in the beginning of your answer I would not need to spend last two hours restoring my VS extensions and syntax coloring. This is mostly my fault, though, I was just too angry and downvoted your answer even though it does work. – Varvara Kalinina Sep 04 '17 at 14:56
  • I almost did that "reset" thing in my VS17, but after reading the comment about it here, I decided to wait with that. My question is - if I save the current settings of my VS, run it with the "reset" option and then import back the settings, will I get VS back with everything I had, but with the "fix" of the reset option, or will the import bring back the issue with it??... – TheCuBeMan Mar 11 '18 at 13:55
  • I haven’t tried that. My guess would be that the fix won’t appear again after resetting and importing settings.. but that’s only what I think – fabricio Mar 11 '18 at 18:25
  • Before trying this and resetting user data, try "clean solution" option mentioned below. – Dinch Jul 27 '18 at 00:14
  • On VS2017 (15.8.1) I tried all the solutions provided for this question. At last, only this solution worked. – Ashish Singh Sep 02 '18 at 09:49
  • @AshishSingh same happened to me but 2 years ago, it’s incredible we are still facing same issue. – fabricio Sep 02 '18 at 14:06
  • for those who still have this problem, maybe this helps: follow this steps: " 1) Right click on "References" in the Solution Explorer 2) Select "Manage NuGet Packages" 3) Under the "Installed" tab search fro "Microsoft.Net.Compilers" 4) Select "Microsoft.Net.Compilers" 5) On the side window of "Microsoft.Net.Compilers" click the update button That should allow you navigate to definitions", you can see the original post here: https://developercommunity.visualstudio.com/content/problem/505489/cannot-navigate-to-the-symbol-under-the-caret-3.html – Victor Labastida Apr 25 '19 at 02:22
  • 2
    As per Anthony's comment below (now the highest rated answer) "closed Visual Studio, deleted ".vs" folder (in the solution folder) then reopened Visual Studio" – rgardler Jun 11 '19 at 05:35
  • Just Cleaning the solution and then Building the solution worked for me. – Sachintha Nayanajith Oct 15 '20 at 05:31
61

I tried David's solution (the one about clicking Empty Symbol Cache option) but it didn't work for me.

How did I solve it?

  • Close all files
  • Clean solution
  • Rebuild solution

For me this error does not make sense but I solved doing this!

joalcego
  • 1,098
  • 12
  • 17
42

Just had the same issue and it seems like there is a problem with VS 2015 and TFS. I got the problem after I merged some files to another branch. Tried several things and it worked:

  • Close all open files and then VS
  • Tools->Options->Debugging->Symbols->Empty Symbol Cache
  • TFS Check in and get latest (For some reason it worked after this)

Not sure why it occurs but this worked for me, it might also be worth to clear TFSTemp folder as mentioned by zvi.

EDIT

This path: %TMP%\TFSTemp can be copy-pasted into windows explorer to access TFS temp

David
  • 703
  • 11
  • 24
  • Emptying the symbol cache didn't work for me. I don't use TFS either. – Jeff Nov 14 '15 at 01:01
  • 4
    Empty Symbol Cache worked for me. Thanks. You need to close all documents first. – toha Feb 09 '16 at 08:36
  • But after I open decument, make breakpoint and debugging my code, the error occurs again. Can anyone help me further? – toha Feb 09 '16 at 08:58
  • @toha There might be a problem to youre symbol file location/server, are you using a custom one or the Microsoft Symbol Server. Try disable/enable this – David Feb 09 '16 at 11:42
  • The problem occured when I try to debug the apps. (Attach to process w3wp) Then, I try to go to definition for function, or variable the error occurs. cannot navigate to the symbol under the caret. Then I need to stop the debugger, and Close All Document, and reopen the document again. Then it back to normal again. Then if I debug again, the error occurs again. So, the answer above maybe is not best answer. Need more investigation about this. Need suggestion please. – toha Feb 11 '16 at 02:09
  • 1
    In my case, only doing "Tools->Options->Debugging->Symbols->Empty Symbol Cache" worked, didn't need to close anything or do anything else, thanks. – Alvaro Rodriguez Scelza Aug 12 '16 at 14:20
  • Works like a charm ! – Sharique Abdullah Sep 19 '16 at 20:22
  • In my case it was an issue with SVN - I had one file in conflicted state and reverting it back from the repo immediately fixed the problem. – Lukasz Matysiak Jan 28 '19 at 13:56
  • 1
    My solution was: 1. Close all files 2. Clean solution 3. Unload all the projects 4. Close VS 5. Open VS (dont open files) 6. Reload all projects 7. Clean solution 8. Build Solution – CABascourt Jul 15 '19 at 17:19
18

The following fixed this for me:

  • In Solution Explorer, right click the solution name.
  • Select "Clean Solution"

After this successfully completed, I no longer received the error, and I didn't have to close and reopen anything.

Chris Szalaj
  • 183
  • 1
  • 4
10

I have the same problem after update visual studio, so this is how do I solve the problem.

  1. Close visual studio.
  2. Delete all .vs folder from my project.
  3. Open visual studio.
  4. Open my project.

Hope this helpful for anyone who has this problem.

wut-excel
  • 2,287
  • 1
  • 15
  • 17
9

Just do it:

  • Close Visual Studio
  • Go to project folder and delete .user file (may be hidden)
  • Open Visual Studio
Helper
  • 125
  • 1
  • 8
  • Thank you!! This is the one that did it for me. Quick and painless. In my case, this was only occurring in one project of the solution so I really didn't want to do anything to affect the whole solution or user settings in VS in general. – Bradley Mountford Sep 26 '18 at 18:55
8

Clean your cache symbols (Tools > Options > Debugging > Symbols > EmptySymbolCache). Open your solution in administrative mode.

this resolved my issue.

user3724031
  • 195
  • 2
  • 7
6

The answer above is correct, but the path is slightly off, try this instead:

%AppData%\..\Local\Temp\TFSTemp
Martin Evans
  • 45,791
  • 17
  • 81
  • 97
6

Close visual studio then remove the hidden file name .vs on that project and open again the visual studio then build the project. Boom! All good!

KhailXpro
  • 298
  • 1
  • 3
  • 10
6

I've done all things above but my problem did not solve (trying to open project by VS 2017),

after that I realized that the problem was my csproj file. My project (mvc)

was created by VS 2015... So I edit my csproj file and replace

<Import Project="..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.0\build\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props" Condition="Exists('..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.0\build\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props')" />

by this :

<Import Project="..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.7\build\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props" Condition="Exists('..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.7\build\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props')" />

It was all about the version of DotNetCompilerPlatform.

(the way that I understood this issue was that I created new mvc project by VS 2017 and compared both csproj files - the new one and the one that created by VS 2015 - )


Additional related info by https://stackoverflow.com/users/15667/xan (since answers are locked)

For me (VS2019 opening an older solution) it was only affecting one project in the solution. The Imports looked like this:

<Import Project="..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.0\build\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props" Condition="Exists('..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.0\build\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props')" />
<Import Project="..\packages\Microsoft.Net.Compilers.1.0.0\build\Microsoft.Net.Compilers.props" Condition="Exists('..\packages\Microsoft.Net.Compilers.1.0.0\build\Microsoft.Net.Compilers.props')" />
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />

The working projects only had the

<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />

line, so I removed the first 2 and intelisense / go to definition etc. started working again.

HOWEVER the web project now wouldn't run due to missing Roslyn csc compiler.

In the end the solution that worked overall was to update the Microsoft.CodeDom.Providers.DotNetCompilerPlatform and Microsoft.Net.Compilers Nuget packages for the project.

xan
  • 7,440
  • 8
  • 43
  • 65
  • Thanks, this fixed one of my older projects not being able to navigate symbols. – lucuma Apr 16 '19 at 20:04
  • Expanded the answer with a similar situation which worked for me in VS2019. – xan May 15 '19 at 10:20
  • For me, I had to remove the two compiler packages entirely. The issue was caused by hand-migrating my csproj from package.config to PackageReference. – Brian May 05 '23 at 19:04
4

Ran into this problem when using F12 to try and go to a method definition.

All of the mentioned items (except the /resetuserdata - which I didn't try because it would be a pain to recover from) didn't work.

What did work for me:

  • Exit Visual Studio
  • From a Command Prompt, go to the folder for your solution and run the following code (this deletes ALL bin and obj folders in your solution):

    FOR /F "tokens=*" %%G IN ('DIR /B /AD /S bin') DO RMDIR /S /Q "%%G"
    FOR /F "tokens=*" %%G IN ('DIR /B /AD /S obj') DO RMDIR /S /Q "%%G"
    
  • Restart Visual Studio. Opening the solution should take a bit longer as it now rebuilds the obj folders.

After doing this F12 worked!

As a side note, I normally place this in a batch file in my solution's folder, along side the .sln file. This makes it easy to run later!

TheHUTMan
  • 150
  • 6
  • Removing `bin` and `obj` folders fixed the problem (rebuild solution did not work for me), so **I think this answer is more usefull** becuase `/resetuserdata` is way too much. – Roman Zinnatov Jan 26 '18 at 19:21
  • 3
    I got the error `%%G was unexpected at this time.` According to https://stackoverflow.com/a/9311607/740639 the double-percent is for use inside a batch file. I switched the two `%%G` to `%G` and the script worked on the command prompt. Sadly, the script did not work for me. – Walter Stabosz May 11 '18 at 21:14
  • Manually deleting bin and obj folder also did the trick for me – Matt Skeldon Aug 04 '22 at 15:06
3

Recently upgraded to VS 2017 15.5.0 and came across this problem. I tried:

  1. Deleting the symbol cache
  2. Deleting my .vs folder.
  3. Rebuilding solution.
  4. Running devenv /resetuserdata

Sadly, none of these worked. I noticed that this was only happening on some projects and not others. On the project where it was failing, I ended up switching all of the framework versions to 4.7.1, did a clean/rebuild and my "Go to Definition" started working again.

billb
  • 3,608
  • 1
  • 32
  • 36
2

I'd say this is due to the new Roslyn C# compiler, in its github issue tracker you can find many of the actual developers encountering this and trying to fix it, but at present it is still open: https://github.com/dotnet/roslyn/issues/9602

I've spent some time around this also, and I lost the battle. But the following workaround I've found works well for me.

WORKAROUND

  1. Change the keyboard shortcut F12 -> Edit.FindAllReferences (for TextEditor). This will find the definition and all references and focus the root node (definition) in the Find Symbol Results.
  2. Now pressing F12, ENTER will do the same as F12 before.

For me it seems to work even better than just GoToDefinition, because:

  • After hitting F12 you can choose a reference instead of the definition by pressing UP or DOWN
  • You can simply cycle between the references and definition just with these few keys (F12, ENTER, UP, DOWN), easy to remember.
LubosTomsa
  • 41
  • 1
2

I'm using VS 2017 15.7.5 and this stopped working for certain test files. I noticed that they were all the new ones I had recently added and that in Solution Explorer there was no arrow available to expand and see the properties / methods.

I excluded and then re-included them into my project and the go to definition command worked again.

hkutluay
  • 6,794
  • 2
  • 33
  • 53
Liam
  • 5,033
  • 2
  • 30
  • 39
1
  1. Check the namespaces of the two classes.
  2. If you are adding classes in the Class library - Make sure you are using the right Project type. There are two class library types. Class Library(Package) and Class Library. (Select the later one as it creates .dll file) which can then be added if needed in other solutions.
Dev
  • 1,451
  • 20
  • 30
1

If you recently installed an add-in, consider uninstalling it. That's what worked for me.

tstuts
  • 454
  • 4
  • 6
  • I recently installed an add-in, and when I loaded solution in the middle and try to use go definition, I got this error. After wait a couple of minutes and all projects loaded, the problem gone, no uninstalling needed. – Tony Dong Mar 18 '19 at 18:12
1

I also faced with the same problem and "Find all references" for selected class has solved this issue.

Artem Ustimov
  • 98
  • 1
  • 5
1

I also came across this once. There is something wrong with TFS in VS 2015.

I followed these steps and it worked

  1. Cleared TFS Cache This might be here:

    C:\Users\(UserName)\AppData\Local\Microsoft\Team Foundation\(Version)\Cache

Note: path may vary based on operating system so don't blame me.

  1. Emptied Symbol Cache

    Tools > Options > Debugging > Symbols > EmptySymbolCache

  2. Restarted Visual Studio (It Might ask for connecting to TFS again)

This Worked for me.:)

Maulik Modi
  • 1,205
  • 12
  • 22
1

Most of the paths submitted by others either don't work or are a little backwards.

Empty this folder:

%localappdata%\Temp\TFSTemp

This worked for me.

Mohannad
  • 124
  • 7
1

It appears you need to have built the project at least once for caret browsing to become available. If you're experiencing this issue on a project you haven't built yet, try building it. That fixed it for me so I thought I'd throw it out here.

Ctrl+Shift+B

trademark
  • 565
  • 4
  • 21
0

Clean solution. Restore nuget packages.

ziaprog
  • 1,497
  • 1
  • 10
  • 11
0

try cleaning the solution or clean your project, this worked for me

Saahithyan Vigneswaran
  • 6,841
  • 3
  • 35
  • 45
0

The following worked out for me like a charm:

  1. I checked the warnings that showed up when I built the Project
  2. Some of them mentioned something about assembly version conflict. Visual studio suggested that I clicked on the warning and hit Enter. A popup window offered to automatically fix the issue and so I did.
  3. Problem solved!
Maher Abuthraa
  • 17,493
  • 11
  • 81
  • 103
0

This weird bug happened to me while importing a Xamarin project into VS15. None of the solutions listed here worked for me. After a day of frustration I also ran into a problem similar to this: Visual Studio "Find" results in "No files were found to look in. Find stopped progress."

When clicking 'find all' in the search dialog, a popup informed me that other files could not be searched through. so i figured the reason 'go to definition' didn't work was due to the same bug, as looking for definitions in the same file did work.

the weird solution in the above link (pressing Ctrl+Scroll Lock or Ctrl+Break a few times) solved both problems for me.

Coloring of the code (which wasn't working when the 'Go to definition' functionality was broken) also immediately returned.

Community
  • 1
  • 1
Jake Walden
  • 523
  • 6
  • 5
0

After doing a "devenv.exe /resetuserdata", my VAssistX fails, so, actually, this reminds me that VAssistX can resolve the problem by Goto Implementation (Alt+G).

macrod
  • 61
  • 6
0

My problem was that I (semi-accidentally) changed the property Build action of the problematic .cs file to Content. Changing it back to Compile did the trick, which makes sense.

okkko
  • 1,010
  • 1
  • 13
  • 22
0

After I read that this particular issue was fixed in the roslyn compiler (see this issue at GitHub), I updated Visual Studio from version 15.0.x to 15.3.1. It works like a charm now.

Franz Wimmer
  • 1,477
  • 3
  • 20
  • 38
0

For me the navigate works just NO XAMARIN SOLUTIONS. That suggestions here DIDN´T WORKS. :( Devenv.exe /resetuserdata not works for me.

My solution was: Re-create the solutions, project, folders and works. No import. Detail: my project was on the VS 2015, the error was on the VS 2017.

0

I had this error for quite sometime now until I couldn't take it anymore so I have tried all possbile solutions above, but none worked for me. I noticed that the error only pops up on a certain project only (like what a user mentioned above) but not on other projects. Because of that, since nothing is working, I cloned my project again on a different folder and it started working again.

user742102
  • 1,335
  • 8
  • 32
  • 51
-2

For some reason my call_name.xaml.vb class had been excluded from the project (it seemed to happen after I got latest version from TFS). I just had to include it again and it works now!

brandonstrong
  • 628
  • 7
  • 21