Categories
c# intellisense resharper syntax-error visual-studio

Visual Studio displaying errors even if projects build

327

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?

9

  • 4

    Do you have ReSharper or any other addon like this installed? They can cause red squiggly lines too.

    Jul 17, 2013 at 14:49

  • 4

    Try deleting the bin and obj folders from each project.

    Jul 17, 2013 at 14:52

  • Errors or warnings? If project builds then it means that these are warnings. Disable all the addons and see how it goes.

    – Ehsan

    Jul 17, 2013 at 14:52

  • We have the same issue with 2 of our machines on VS 2013 RC candidate. No Resharper installed though. The delemma here is that even though it builds without issues, no intellisense will work because it cannot ‘resolve’ namespaces and objects. Really weird. Works on 5 other machines perfectly.

    – Ryk

    Sep 13, 2013 at 1:13

  • Unresolved conflicts in Team Foundation Server can also be a source of this problem. Getting the latest version may report that it is successful and all files updated, but that’s not always true. If you go to Team Explorer > Pending Changes > Actions drop-down > Resolve Conflicts and click “Get All Conflicts” it should show you if there are any unresolved conflicts that you need to fix.

    Jan 21, 2014 at 18:01

339

If you have ReSharper, try emptying the ReSharper cache:

In menu, ReSharper > Options > Environment > General > Clear Caches

and disabling and re-enabling ReSharper:

In menu, Tools > Options > ReSharper > General > Suspend / Restore

2

  • 1

    this worked for me. I tried deleting the .vs folder and deleting all the bin and obj folders. It was clearing Resharper cache that finally fixed it for me in VS2022

    Oct 21 at 10:46

  • @Emma Middlebrook I tried this in Visual Studio 2022 but it did not work. Only removing .NET 7 from my computer fixed it for me. Resharper 2022.2.4

    – Natrium

    Nov 15 at 10:35


228

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.

7

  • 7

    The Resharper steps didn’t work for me either, but this did. Thanks!

    Nov 3, 2015 at 16:18

  • 4

    Your solution fixed it for me, after restarting visual studio. Thanks! 🙂

    – Moulde

    Dec 17, 2015 at 13:32


  • 1

    VS2015 – I even had 1 project that wouldn’t build but I could tell from the errors that it should have. I didn’t have to close VS. Just closed the solution, delete .suo, and reopen the solution. Problem solved.

    – TTT

    Jan 8, 2016 at 16:16

  • 13

    Still works with VS2019, thank you! The .suo file there is located at .vs/[solution_name]/v16.

    Jul 17, 2019 at 15:22

  • 6

    VS2019, I nuked the .vs directory, it was recreated on the next build–bogus error gone.

    Sep 6, 2019 at 21:46

144

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.

10

  • 10

    I just tried unloading that project and reloading it, and this worked.” I feel like I’m contributing to a cargo cult, but I ended up loading and unloading (with random cleans & builds in between), and eventually struck gold. So weird. This is with VS 2017.

    – ruffin

    Oct 12, 2017 at 19:11


  • 2

    @ruffin – hehe. I think every answer to this question is a “cargo cult”, but I believe mine is the quickest and least intrusive. 😉

    – TTT

    Oct 12, 2017 at 22:05

  • 2

    Deleting the entire .vs folder did it for me in VS 2017 Community with ReSharper

    Apr 2, 2019 at 10:57

  • 3

    Unloading and reloading worked for me in VS 2019 CE too

    Apr 16, 2019 at 9:49

  • 1

    Deleting .vs folder worked for me in VS 2019 with no ReSharper, just plain VS. THANKS!!!

    Jan 13, 2020 at 14:52