locked
"Go To Definition" Doesn't Work Sometimes RRS feed

  • Question

  • I like to right-click on a message and choose "Go To Definition" to look at the code for a method.  But sometimes this doesn't work properly, taking me to a different place in the code.  I figured that I'd just have to rebuild the project but that doesn't seem to correct the problem.

    Why does this occur and how do I correct it?

    Robert W.
    Vancouver, BC
    Thursday, April 26, 2007 2:33 AM

Answers

  • The solution you gave did not work for VC 6. Here is what I did to get it to work in VC 6:
    1) Delete the bsc file (<projectname>.bsc)
    2) Use the 'Go to definition' option on any symbol. VC will ask you if you want to rebuild the project with source browser info - choose 'Yes'

    Wednesday, July 18, 2007 8:26 PM
  • When I seperate the code from a class and copy it to another class in a different file, I sometimes forget to import the namespaces used by that code. So, when I get errors, I go to the error, use smart tags to automatically import (using) the needed namespace. Wich in turn adds a line to the file and after that, when I go to another error by double clicking on the error in error window, It takes me to the one line above the error. This behavior goes away simply recompiling / building the application, not rebuilding is required.

     

    This behavior is wierd but seems like the line references are not updated when changes are made to the file until you rebuild it again. Check out the problem you are facing, there must be some specific difference between the line it takes you to and the actual line. The reason behind this must be some changes made by you.

    Tuesday, May 1, 2007 6:50 AM
  • I also experienced this often in Visual Studio 2003. The line I was taken to was almost always a dozen or so lines above the actual line. I never figured out the source of this problem. Since moving to Visual Studio 2005 I have not experienced it.
    Thursday, May 10, 2007 10:48 PM
  • I figured out how to solve my problem, maybe it will also work for some of you.

    I followed these steps:
    1 -Close the solution.
    2- Delete the intellisense database file for the solution: <name of the solution>.ncb
    3- Open the solution. 
    4- Rebuild the solution.

    (I believe either step 3 or 4  regenerates the intellisense database file when it is missing)
    Intellisense, "go to defintion" and "find all  references" should be working again.
    Monday, June 4, 2007 2:45 PM

All replies

  • What do you mean different place? Also which version of studio are you using? Can you reproduce the steps for us and detail them?
    Friday, April 27, 2007 11:14 PM
    Moderator
  • I mean that the cursor literally goes to another row in the file, and not always to a method header either.

    It's almost as if some indexing has gotten messed up.

    I am using VS2003 but am about to upgrade to VS2005.

    I just assumed that someone else would have experienced this.

    Robert

    Friday, April 27, 2007 11:41 PM
  • When I seperate the code from a class and copy it to another class in a different file, I sometimes forget to import the namespaces used by that code. So, when I get errors, I go to the error, use smart tags to automatically import (using) the needed namespace. Wich in turn adds a line to the file and after that, when I go to another error by double clicking on the error in error window, It takes me to the one line above the error. This behavior goes away simply recompiling / building the application, not rebuilding is required.

     

    This behavior is wierd but seems like the line references are not updated when changes are made to the file until you rebuild it again. Check out the problem you are facing, there must be some specific difference between the line it takes you to and the actual line. The reason behind this must be some changes made by you.

    Tuesday, May 1, 2007 6:50 AM
  • I also experienced this often in Visual Studio 2003. The line I was taken to was almost always a dozen or so lines above the actual line. I never figured out the source of this problem. Since moving to Visual Studio 2005 I have not experienced it.
    Thursday, May 10, 2007 10:48 PM
  • I have the same problem. That is definitely a bug of VS. When i have such problem, i return to previous code file and again invoke Go To Definition or use the members combo at the top od code editor to again select the requested member, and then it goes to the right place. This is happening only when the targeted code file is big, and not with smaller ones.
    Friday, May 11, 2007 10:40 AM
  • HI

     

    are you talking about C# or C++?

     

    if it is C#, by "Go to definition" do you mean

     

    putting a caret on a type, and select context menu "go to definition" (shortcut)F12

     

    or

     

    selecting a row in a tasklist (error/warning/user comment/Find symbol list)?

     

    - heejae

     

     

    Saturday, May 12, 2007 8:16 PM
  • I have the same problem with VS2005 when using C++.

    When using "Go to definition" or "Find All References" I get rarely the correct behavior, most of the times I am sent to the "Resolve Ambiguity" dialog where I am presented choices for methods in MFC libraries and other windows libraries, these methods have names completely different to the name I am looking for. Other times I don't even get the "Resolve Ambiguity" dialog, just a message telling me the definition does not exist.

    Furthermore, when using the "Find All References" sometimes VS crashes. Ah, and btw, intellisense is not working in any of the files presenting this "Go to definition" erratic behavior.

    If it is of any help to the programmers, I noticed the problem started when intellisense began to fail on some .cpp files where I had local functions declarations and definitions. But now it is gotten much worse.

    Thanks for any help
    Thursday, May 31, 2007 3:41 PM
  • I figured out how to solve my problem, maybe it will also work for some of you.

    I followed these steps:
    1 -Close the solution.
    2- Delete the intellisense database file for the solution: <name of the solution>.ncb
    3- Open the solution. 
    4- Rebuild the solution.

    (I believe either step 3 or 4  regenerates the intellisense database file when it is missing)
    Intellisense, "go to defintion" and "find all  references" should be working again.
    Monday, June 4, 2007 2:45 PM
  • The solution you gave did not work for VC 6. Here is what I did to get it to work in VC 6:
    1) Delete the bsc file (<projectname>.bsc)
    2) Use the 'Go to definition' option on any symbol. VC will ask you if you want to rebuild the project with source browser info - choose 'Yes'

    Wednesday, July 18, 2007 8:26 PM
  • Anon, your solultion does work!
    Tuesday, August 14, 2007 11:50 AM
  • I am using VS 2008 beta 2. For me also 'Go to Reference' and Intellisence both stopped working. After looking for sometime, I found out that in one of the XAML usercontrols, I was missing close </UserControl> tag at the end of the file. When I added that, life was normal.

     

    Hope this helps atleast some of you.

    Thursday, August 23, 2007 11:32 AM
  •  YesK wrote:

    I am using VS 2008 beta 2. For me also 'Go to Reference' and Intellisence both stopped working. After looking for sometime, I found out that in one of the XAML usercontrols, I was missing close </UserControl> tag at the end of the file. When I added that, life was normal.

     

    Hope this helps atleast some of you.



    The point of a beta is to find out these things. You should check for the bug in the Connect database for Visual Studio, if it is not there, then report it as a bug so it can be looked at. Connect: Visual Studio and the .NET Framework
    • Proposed as answer by robert_nsu Monday, May 17, 2010 7:24 PM
    Thursday, August 23, 2007 3:20 PM
    Moderator
  • I am using VS 2008 version 9.0.21022.8 RTM

    My source code is in C++. When i am trying to use "Go To Definition" it points to function Declaration rather than Definition. How we can make it to work?

     

    Thursday, April 22, 2010 9:48 AM
  • In C++ it will go to whatever element makes the compiler happy for the compilation unit.  If you are using forward references, for example, it'll generally jump to that.  This is partially because C++ allows for an identifier to be given multiple declarations provided there is only one definition.  That definition might or might not be in the code being compiled.  In other words it is unreliable in most C++ apps.

    Personally I will try Goto Definition first and if that doesn't work then Find References.  Also, please post C++ questions in the C++ forums.  This forum is for C#.

    Michael Taylor - 4/22/2010
    http://msmvps.com/blogs/p3net

    Thursday, April 22, 2010 1:37 PM
    Moderator
  • Thanks! This worked for me except I didn't have to delete the intellisense database. All I had to do was rebuild the code.

    Saturday, November 5, 2011 6:48 PM
  • These steps worked perfect for me,

    Thanks.

    Friday, August 24, 2012 3:08 PM