Visual Studio compiles fine, but it still shows red lines

76,627

Solution 1

Delete the contents of the temporary ASP.NET folder and then rebuild. It'll either be in your user folder (for IIS Express - \AppData\Local\Temp\Temporary ASP.NET Files) or the Windows directory (for IIS - C:\Windows\Microsoft.Net\Framework\vx.xx\Temporary ASP.NET Files)

Paths are off the top of my head and may not be correct

Solution 2

Visual Studio 2017:

Closing Visual Studio and removing the .vs folder located in the solution directory worked for me.

This folder has a hidden attribute. You may need to change settings in folder options to show hidden files.

Solution 3

For me, this issue got fixed when I unloaded and reloaded the project again.

Solution 4

I had this issue and it was related to ReSharper.

Solution steps for me:

  1. Disable ReSharper

    VisualStudio\Tools\Options\ReSharper Ultimate\General\Suspend Now

  2. Build Solution

    (Ctrl + Shift + B)

  3. Re-enable ReSharper

    VisualStudio\Tools\Options\ReSharper Ultimate\General\Resume Now

Solution 5

Just had this problem while working with a solution created in Visual Studio 2012 but running in 2013. I closed Visual Studio, deleted all \bin and \obj directories and the problem was gone.

Share:
76,627

Related videos on Youtube

Lost
Author by

Lost

Updated on January 21, 2022

Comments

  • Lost
    Lost over 2 years

    I am using Visual Studio 2012 and it was working all fine until I started observing some funny behavior. When I open my code it shows red Underlines which we usually see when there is an error in our code. Surprisingly, the code compiles all fine. I have made following observations that are not normal at all.

    1. Red underlines in the code
    2. While cleaning or building the solution no error.
    3. Red underlines go away for some time after I build/clean the solution, but they come back eventually.
    4. Because of this, my IntelliSense stopped working.
    5. I can not right click on any component and go to its definition.

    Any ideas?

    • matth
      matth over 10 years
      What code is showing underlines? Can you provide examples?
    • Max
      Max over 10 years
      Are you perhaps running old code? Try a small implementation that shows something, if nothing happens you might be running old code.
    • AlG
      AlG over 10 years
      Are you running Reshaper or any other tool that may be doing the underlines?
    • Pierre-Luc Pineault
      Pierre-Luc Pineault over 10 years
      Is this on all code files? It happened to me once when I opened a file which was not from my solution, not being able to go to the definition gave it away for me.
  • Oleg Kyrylchuk
    Oleg Kyrylchuk over 9 years
    I was using Resharper. You can disable ReSharper by using the Suspend button in menu Tools -> Options -> ReSharper. Then Resume it, it helped me.
  • Kyle
    Kyle almost 9 years
    Alternatively, if this is just affecting the one project/solution and you're using git with the appropriate ignores in place for temporary files, try commiting you changes, deleting your working copy and force checkout your branch.
  • Sнаđошƒаӽ
    Sнаđошƒаӽ over 7 years
    I don't see a solution in your answer. "It seemed intellisense was not able to resolved dependencies on its own..." - are you saying by "browsing through the classes, structures" you helped intellisense resolve the dependencies?
  • Robert Columbia
    Robert Columbia over 7 years
    @Sнаđошƒаӽ I think that is exactly what he is saying.
  • Sнаđошƒаӽ
    Sнаđошƒаӽ over 7 years
    @RobertColumbia No offence to OP, but I think that's just ridiculous.
  • Robert Columbia
    Robert Columbia over 7 years
    @Sнаđошƒаӽ well that is what he is saying. If you think that strategy is not helpful, downvote the answer.
  • irsis
    irsis over 7 years
    @Sнаđошƒаӽ Well, I reached to post because I was also facing the same problem. First I tried all the answers before I posted what worked for me Like others also have answered based on there experience. I don't see anything wrong with it. Instead, it might help someone else too.
  • nico
    nico over 6 years
    I was facing the same issue and this was the only way it got fixed. After VS indexing was done, none of the includes could be resolved. Then I start opening some files and VS seemed to find the correct location for the classes I was working on. As a side note, I was working on a big project structured with CMAKE.
  • secretwep
    secretwep over 6 years
    For VS 2017, this solution worked where none of the others on this page did (like cleaning temp folders and cleaning /bin and /obj). The .vs wasn't "hidden" on my system as mentioned (whereas e.g. my .git folder was of course, so I could tell the difference).
  • Lost
    Lost over 6 years
    what if the error is in Visual studio for Mac? what would be the path for this folder?
  • Alx
    Alx about 6 years
    Removing the just the .suo file (which is in the .vs folder) also works
  • MusicAndCode
    MusicAndCode almost 6 years
    I needed to close and open VS after and it works. Thanks
  • Amit Kulat
    Amit Kulat over 5 years
    I tried deleting the .suo file but it gets recreated again when I restart VS 2017
  • VeganHunter
    VeganHunter over 5 years
    @AmitKulat Yes, .suo file is a structured storage that is created by Visual Studio and it contains a bunch of settings. Due to some bug it stops working properly. So, when you remove it, it will be recreated with correct default settings.
  • Alex Fainshtein
    Alex Fainshtein over 5 years
    @AmitKulat Very often deleting .suo is enough, but not always. Deleting the whole .vs (containing .suo) is more "potent". And yes, .vs will be recreated when you reopen the solution.
  • nilsK
    nilsK over 5 years
    The 'Clear cache' button on the Environment | General page of ReSharper options solved my problem. Thanks for the hint though!
  • Bob Stein
    Bob Stein about 5 years
    “Unsupported ... This version of Visual Studio is unable to open the following projects...” — a rather heart-stopping popup after deleting the .vs directory. But it appears benign. Clicked OK and the solution opened anyway, after a Migration Report. This may be an unrelated issue that was dormant until .vs was deleted. Reporting here for posterity.
  • Albert Romkes
    Albert Romkes about 5 years
    This also works for Visual Studio 2019 (Preview. Deleting the .vs folder)
  • Nandolcs
    Nandolcs about 5 years
    After days of research, unload/load projects and many .vs folder removals, this was the root cause of my problem so I consider this a valid answer. May someone, somewhere bless you my son.
  • DKR
    DKR about 5 years
    perfect solution
  • Muhammad Saqib
    Muhammad Saqib about 5 years
    Worked for me. Yes. ReSharper was the problem.
  • Lemonseed
    Lemonseed almost 5 years
    I had the same/similar problem. One class that was clearly in the project, but Visual Studio would not recognize with color-coding, and each reference to it showed up as an error (even though compiled fine). Deleting the hidden .vs folder did the trick.
  • bahramzy
    bahramzy about 3 years
    Suspend Now solves the issue. Resume Now - the issue is there again.
  • TRPh
    TRPh about 3 years
    After I did this, the code wouldn't compile. Visual Studio 2017 seemed to have forgotten it was in C++17 mode, even though C++17 was still selected.
  • Harshan
    Harshan almost 3 years
    Close VS and delete .VS folder worked for me too. I'm using mac m1 with Visual Studio 2019.
  • Peter Mortensen
    Peter Mortensen almost 3 years
    How many files did you have to add to the new Solution file?
  • Peter Mortensen
    Peter Mortensen almost 3 years
    How exactly? Refresh in what sense? Can you add instructions to your answer (a how-to)? But without "Edit:", "Update:", or similar - the answer should appear as if it was written today.
  • Peter Mortensen
    Peter Mortensen almost 3 years
    Can you be more specific than "do a rebuild all" and "do a clean"? Exactly how should it be done? Can you add the exact menu commands, etc. that should be invoked (or at least provide some hints)? But without "Edit:", "Update:", or similar - the answer should appear as if it was written today.
  • HardcoreGameDev
    HardcoreGameDev over 2 years
    Consider reading others' answers in an old post. You can just upvote this answer, this is the Stack Overflow way of saying thank you. Instead of posting a duplicate.
  • Nickson Yap
    Nickson Yap over 2 years
    This is very likely a Visual Studio Code command, not Visual Studio
  • Dave Stuart
    Dave Stuart over 2 years
    Windows 10 with Visual Studio 2019. Deleting the .vs folder worked for me! Thanks!
  • NJS
    NJS about 2 years
    If resuming ReSharper causes the issue to reappear, you may need to upgrade to a newer version of ReSharper. Older versions simply don't support newer C# features
  • Octopus
    Octopus almost 2 years
    Seems like it momentarily, but if you wait a few minutes all the squiggles will come back.