Rick Strahl's Weblog  

Wind, waves, code and everything in between...
.NET • C# • Markdown • WPF • All Things Web
Contact   •   Articles   •   Products   •   Support   •   Advertise
Sponsored by:
West Wind WebSurge - Rest Client and Http Load Testing for Windows

Fixing Visual Studio Intellisense Errors


:P
On this page:

It's always fun when Visual Studio (ie @drunkvs) can't recite the alphabet backwards: The code below builds just fine when running through the compiler, but Visual Studio displays Intellisense errors in the Error Window and in the code with underlined squiggles:

The actual build of the code succeeds, but Intellisense is flagging several classes as missing even though they clearly exist and clearly compile properly.

IntelliSense is High!

So IntelliSense sometimes goes off the rails and if you see errors in your project that don't make sense, first check to see if the errors are related to Intellisense.

Notice the drop down in the error list that lets you see Build + Intellisense which, in the case above produces 3 errors, but no errors if I just show Build Only:

Note the Intellisense error drop down is a new feature so you may not see it in older versions of Visual Studio. Not sure when it arrived but it was in one of the late VS 2015.x updates.

Clearing up Intellisense

There's usually a simple solution when IntelliSense decides to sleep one off:

Delete the .vs folder

The .vs folder holds solution related temp data including the .suo file that caches intellisense and some debug data. That folder also holds Web site configuration data for Web projects and a few other things. It's safe to delete this folder - Visual Studio recreates it when it's missing.

Older versions of Visual Studio (prior to VS 2015) didn't have a separate folder and dumped that same information into files in the solution's root folder.

In these older versions you can fix Intellisense issues by deleting the Solution's .suo file. Deleting the .vs folder in newer version nukes the .suo file which is responsible for cached IntelliSense and also some cached Debug data. When VS acts up and reports whacky errors that seem wrong, the burning down the .suo file is a nice quick thing to try first.

To do this:

  • Shut down VS
  • Nuke the .vs folder or the .suo file
  • Restart VS

The .suo file contains cached IntelliSense data and once that file is off, no amount of recompilation or clearing the project is going to help. Nuke the .suo file. or in VS 2015 or later the .vs folder and get back to sanity.

Compiler Errors?

I haven't run into this problem very frequently but when it does happen it's usually quite vexing resulting (for me at least) in a flurry of deleting output folders.

I have a standard set of steps I tend to go through when I get compiler errors that are wrong. Well, usually it's me who's wrong, not the compiler but on occasion I get to be right and the compiler is really wrong.

If you have errors that show under the Build Only dropdown, then the issue isn't Intellisense.

This has gotten a lot better, but for a while invalid compiler errors were a big problem with the .NET SDK projects (.NET Core / .NET Standard) and in those cases the solution for me usually is (and still occasionally is):

  • Delete the obj folder completely
  • Delete the bin folder completely

While Visual Studio's Clean project feature is supposed to address this, Clean will only clean up files the project knows about. If you've removed or renamed assemblies there may still be left over files in project output folders and deleting them cleans out the project completely.

This often fixes odd left over file issues that can cause strange compilation behavior. I never really considered Intellisense failure previously because Visual Studio didn't differentiate compiler and IntelliSense Errors (or more accruately I didn't notice the dropdown). I'd see errors in the Error list, yet my project would compile successfully, which was even more confusing.

Back to the Straight And Narrow

It's nice that Visual Studio now explicitly shows these errors separately as Build and Intellisense errors, so you can take the sepearate actions to clean up this mess. In the past when the errors weren't separated it was even more confusing with compiles succeeding, but the error list showing errors.

Now as to the cause of any of these errors? @drunkvs has some cleaning up to do after the barf fest of the previous night...

Posted in Visual Studio  

The Voices of Reason


 

Jesse C. Slicer
August 08, 2018

# re: Fixing Visual Studio Intellisense Errors

I have that drop-down in VS 2015 (14.0.25431.01 Update 3).


Rick Strahl
August 08, 2018

# re: Fixing Visual Studio Intellisense Errors

@Jesse - thanks for the heads up. Updated the post. I guess I must have just not noticed that this has been there. Maybe even longer than VS 2015?


Paul
October 28, 2018

# re: Fixing Visual Studio Intellisense Errors

One thing to add to this, particularly in older versions of VS, is that hibernating or sleeping your laptop, after a long day's night, can also play hokey with the old IntelliSense.


Robert
September 15, 2019

# re: Fixing Visual Studio Intellisense Errors

I have exactly this problem. The program compiles, but Intellisense is giving lots of errors. This sounds as very useful information to fix that, but where is the .vs folder located ??? Can't find it with Windows search, I am using VS2017...


Basl
October 01, 2019

# re: Fixing Visual Studio Intellisense Errors

Robert, the .vs folder is hidden by default, so make sure you have Windows Folder Options set so that hidden folders are visible. But, you should find the .vs folder in the same directory as the .sln file.


Mike Salway
May 14, 2020

# re: Fixing Visual Studio Intellisense Errors

I've still got this problem in the latest Visual Studio 2019, clearly Microsoft aren't very interested in fixing it. If you've got a lot of solutions, it can get very annoying. This command should destroy all .vs folders recursively from wherever you run it. Test it first though!

FOR /d /r . %%d IN (.vs) DO @IF EXIST "%%d" rd /s /q "%%d"


Ben
November 17, 2020

# re: Fixing Visual Studio Intellisense Errors

Just in case someone faces intellisense issues after migrating a project to VS2019 or after a VS update. See here.

Analyze > Build and Suppress Active Issues is a very helpful thing 😉


Rovert
February 15, 2021

# re: Fixing Visual Studio Intellisense Errors

I ran into this same issue but couldn't find any relief on the interwebs. However, I finally found a solution after a few hours of digging.

Because I'm using Blazor, this may or may not apply to your solution, but to get rid of the phantom errors I simply deleted the files in the following folder, closed, and then re-opened the solution: C:\Users<Username>\AppData\Local\Temp\VSFeedbackIntelliCodeLogs\Suggestions\

I think what's happening is that the .cshtml.cs file gets deleted, but Intellisense doesn't recognize it's gone and continues to serve up errors using some cached values stored on disk. The offending files appear to be in the subfolders of \Suggestions, specifically: ...\Suggestions<guid>\output\versions<classname>.cshtml.g.#.cs


Frank Paynter
July 22, 2021

# re: Fixing Visual Studio Intellisense Errors

Thanks - nuking the .vs folder worked for me when intellisense could no longer connect a line number to a function name


Matt
January 07, 2022

# re: Fixing Visual Studio Intellisense Errors

So we had this issue recently in VS 2019, with an older project. It wasn't just IntelliSense showing errors that weren't really there, we also had an issue where we couldn't navigate to certain references in the project. The issue was in the project file. We had multiple references to different Microsoft.Net.Compilers & Microsoft.CodeDom.Providers.DotNetCompilerPlatform versions. After cleaning these up...everything was gravy. Hope this helps someone.


Marty
March 16, 2022

# re: Fixing Visual Studio Intellisense Errors

THanks - been battling with this for months!


Paul Gruet
March 22, 2022

# re: Fixing Visual Studio Intellisense Errors

Deleting the .vs file works, but the problem comes back quickly. I didn't see the problem at all until updating Visual Studio (Microsoft Visual Studio Community 2019, Version 16.11.11) > Does anyone know of a way to permanently fix this?


DaveG
July 14, 2022

# re: Fixing Visual Studio Intellisense Errors

Just updated VS2022 and had this problem. Code compiled fine but lots of intellisense issues. Deleting the .vs folder cleared it up. Saved me a few hours poking around to figure it out myself....


West Wind  © Rick Strahl, West Wind Technologies, 2005 - 2024