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."
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?
This question is related to
c#
visual-studio
visual-studio-2015
Just do it:
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!
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:
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
The following worked out for me like a charm:
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:
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!
I also came across this once. There is something wrong with TFS in VS 2015.
I followed these steps and it worked
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.
Emptied Symbol Cache
Tools > Options > Debugging > Symbols > EmptySymbolCache
Restarted Visual Studio (It Might ask for connecting to TFS again)
This Worked for me.:)
The following fixed this for me:
After this successfully completed, I no longer received the error, and I didn't have to close and reopen anything.
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?
For me this error does not make sense but I solved doing this!
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.
The answer above is correct, but the path is slightly off, try this instead:
%AppData%\..\Local\Temp\TFSTemp
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.
Clean your cache symbols (Tools > Options > Debugging > Symbols > EmptySymbolCache). Open your solution in administrative mode.
this resolved my issue.
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.
Clean solution. Restore nuget packages.
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
For me it seems to work even better than just GoToDefinition, because:
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
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.
If you recently installed an add-in, consider uninstalling it. That's what worked for me.
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.
I also faced with the same problem and "Find all references" for selected class has solved this issue.
try cleaning the solution or clean your project, this worked for me
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.
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).
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.
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.
Recently upgraded to VS 2017 15.5.0 and came across this problem. I tried:
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.
I have the same problem after update visual studio, so this is how do I solve the problem.
Hope this helpful for anyone who has this problem.
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!
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.
Source: Stackoverflow.com