"Go To Definition" in Visual Studio only brings up the Metadata

Viewed 105289

I am working in a Web Project in Visual Studio 2008. When I hit F12 (or right-click and select Go To Definition) Visual Studio is consistently going to the Metadata file instead of going to the source.

Some Points:

  • All the source code is C#, there is no VB.Net
  • All the projects are in the same solution
  • Everything is a project reference as opposed to a file reference (checked and double-checked)
  • I have tried the Clean/Rebuild Solution approach (even to the point of clearing out the Temp directory, Temporary ASP.NET Files directory, etc).

Has anyone else seen this behavior and/or know how to fix it?

30 Answers

Well, another developer found the answer. The specific project we had an issue with was originally added as a file reference, then removed and added as a Project Reference. Visual Studio however, kept both in the csproj file for the web site, causing the issue. He went in and manually edited the csproj file to remove the file reference to the problem project and all is fixed now

It happens when you don't add reference as a project but point to a dll or exe using Browse tab in Add Reference dialog. If you add reference using Projects tab you should go directly to the source code when you select Go To Definition.

However, if you install ReSharper, you'll go to source code even if you added your reference to a dll/exe using Browse tab.

For those using VS 2017 (I'm at version 15.3.4 at this moment) here are the simple steps:

  1. Open your solution in Windows Explorer and close down Visual Studio
  2. In the explorer menu, select View and ensure that the "Hidden items" checkbox is marked
  3. Navigate to the subfolder .vs\[your solution name]\v15
  4. Delete the .suo file
  5. Restart VS and build your solution

That fixed it for me: F12 opened the actual source file, not the "from metadata" version.

Remove the reference dll, Build (will get errors), ADD THE reference (you removed) then build again ... F12 on your function should then work (worked for me).

#1

Check "View - Object Browser" and if you see more than one assembly with the same name - that's why your getting this error.

For us it was a bug in VS 2019:

If you have ASP.NET "Razor helpers" in App_Code folder the Visual Studio 2019 interprets that as a different assembly but with the same name, that hides the actual assembly.

There's no fix for that other than rewrite those helpers to partial views or HTML helpers (you will have to do that anyway if you plan migrating to .NET Core).

See this workaround on MS's site and please upvote the bug there so MS fixes it

https://developercommunity.visualstudio.com/solutions/1008795/view.html (please upvote)

#2

Another reason why same assembly can be loaded twice in the object browser is if you have a unit-test project that starts iis-express process and never kills it properly.

Below steps worked for me.

  1. Go to .csproj file
  2. Open it in Notepad Go to line where dll is referred.<Reference Include="">
  3. Delete the line

    <SpecificVersion>False</SpecificVersion> 
    or 
    <SpecificVersion>True</SpecificVersion>
    

After deleting dll files from Visual Studio first and adding them back manually from Solution Explorer --> Website --> Add --> Reference and enabling 32-bit Applications in IIS fixed it for me.

VS2017 VB.Net Windows 10 Pro - I use an assembly names "SharedCollection" which includes a VB Module named MyGlobals. One of the globals is a FileVersion. References showed metadata and the Windows Service that referenced it had an outdated setting. I had tried some of the SUO remedies above and none of them worked.

This Worked

I deleted and recreated the project reference for ShareCollection in References.

This can happen if you're trying to jump to the definition in a project that has been unloaded (Unavailable). Right-click the unloaded project and select "Reload Project".

I modified the .csproj file and in the Reference -> HinPath changed obj to bin and it solved the problem.

I had a variation of this issue, where when I loaded my solution my referencing project had errors until I compiled the project it was referencing. At that point the errors disappeared but F12 took me to metadata.

The issue was a dependency in the project being referenced that conflicted with a dependency in the referencing project. I manually removed dependencies from the project being referenced until one of them resolved the errors in the referencing project. After that I was able to F12 to the actual code, and the project would load without errors.

If anyone knows exactly why this happens I'm interested to know in the comments.

This little trick solved it for me - unload the referencing project from the solution and then just reload it

Best guess is that you don't have debug information. Maybe you have multiple copies of your assembly on disk and it doesn't have the .pdb file with it.

Do a search for your assembly names from your projects and delete them all and rebuild.

Related