I have a problem with Visual Studio on a C# solution. It displays totally random errors, but the projects build. Right now, I have 33 files with errors, and I can see red squiggly lines in all of them.
I tried cleaning / rebuilding the solution, closing Visual Studio and even restarting my computer. I can modify .cs files and I see the changes in the solution.
Does anyone have an idea about why it does that?
Clearing Resharper’s cache did not help in my case, tried suspend/restore, and also Repair Resharper, using latest download off JetBrains’ website – neither of these helped. This is after I tried close/reopen VS, restart my machine, repeat, Build/Rebuild and combination thereof.
It’s interesting that suspending Resharper seemed to solve the problem after the 2nd restart of VS, but it was back after I enabled Resharper <– I tried to do this sequence 2-3 times to ensure the pattern.
Anyway, I was still having issues when I found this article:
So I deleted the hidden .SUO file on the same folder level with solution, and it magically solved all reds.
Note – for Visual Studio 2015, the .SUO file is in .vs/[solution_name]/v14 hidden folder.
tldr; Unload and reload the problem project.
When this happens to me I (used to) try closing VS and reopen it. That probably worked about half of the time. When it didn’t work I would close the solution, delete the .suo file (or the entire .vs folder) and re-open the solution. So far this has always worked for me (more than 10 times in the last 6 months), but it is slightly tedious because some things get reset such as your build mode, startup project, etc.
Since it’s usually just one project that’s having the problem, I just tried unloading that project and reloading it, and this worked. My sample size is only 1 but it’s much faster than the other two options so perhaps worth the attempt. (Update: some of my co-workers have now tried this too, and so far it’s worked every time.) I suspect this works because it writes to the .suo file, and perhaps fixes the corrupted part of it that was causing the issue to begin with.
Note: this appears to work for VS 2022, 2019, 2017, and 2015.