Go To Definition: “Cannot navigate to the symbol u

2019-01-16 13:41发布

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?

30条回答
一夜七次
2楼-- · 2019-01-16 14:17

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!

查看更多
戒情不戒烟
3楼-- · 2019-01-16 14:19

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.

查看更多
Explosion°爆炸
4楼-- · 2019-01-16 14:20

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

查看更多
老娘就宠你
5楼-- · 2019-01-16 14:20

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 goto definition command worked again.

查看更多
Viruses.
6楼-- · 2019-01-16 14:22

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.

查看更多
ら.Afraid
7楼-- · 2019-01-16 14:23

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!

查看更多
登录 后发表回答