Intellisense and navigation to references and definitions not working in VS2022

335 views Asked by At

WARNING: I have posted this on Reddit a few weeks ago but never got a response.

I have obtained a large .NET solution from a third-party, and I'm having the following issues with it:

  • Right click > Go to Definition for a symbol imported from a namespace defined either in a PackageReference or ProjectReference results in the following popup:

enter image description here

  • Right click > Find all references for a symbol belonging to a referenced namespace (DLL, project or NuGet package) yields no results, only the following information message in the "Find References" pane

enter image description here

  • Intellisense does not work for symbols belonging to referenced namespaces. They are simply not highlighted:

All the above features work fine for symbols defined in the System namespace or the current namespace. Other solutions on my local machine do not exhibit this behavior and work fine. Things I have tried:

  • Setting Tools > Options > TextEditor > C# > Advanced > Run background code analysis for to Entire Solution as well as
  • Enabling CodeLens
  • Deleting the .vs folder
  • Cleaning and Rebuilding, both of which succeed but don't fix the issues I've described above.

None of these things have worked, so I'm beginning to think something more fundamental is going wrong with this particular solution. I can't for the life of me figure out what's wrong with it. What could cause symbols to not get recognized for a solution in Visual Studio 2022? How can I further isolate the root cause of the problem?

1

There are 1 answers

1
user32882 On BEST ANSWER

I finally figured it out. Here's how:

  • Created an empty, dummy solution inside the directory where the other (third-party) solution is located
  • Opened the dummy solution and created two projects:
    • A console app called ConsoleApp1
    • A class library called ClassLibrary1 containing one class called Class1
  • Referenced ClassLibrary1 from ConsoleApp1, and added code in Program.Main referencing Class1
  • Observed that Class1 symbol in ConsoleApp1 was not highlighted and not navigable, similar to my real use case.
  • Ensured that my dummy solution builds with no errors.

I then started deleting stuff from the original solution. I thought it might take forever, considering the size of the codebase and the sheer amount of stuff it contains. First I deleted Directory.Build.props, Class1 was still not navigable, though my dummy build was fine. The Directory.Build.props file also imports a Directory.Build.targets file, so I deleted that as well. Lo and behold, Class1 lit up in green and became navigable. So then I restored Directory.Build.targets, and Class1 was no longer navigable, and I started deleting various property and item groups from Directory.Build.targets until I identified the offending lines:

<PropertyGroup>
  <DisableRoslynDesignTime Condition="...">true</DisableRoslynDesignTime>
</PropertyGroup>

It turns out that, because most of the other developers on the project use Resharper, they want to turn off Roslyn at design time because Resharper has it's own analyzer. Since I prefer not to use Resharper, I had disabled it for this particular solution.

There's an article which says more about this configuration option.