Visual Studio compiles fine, but it still shows red lines

C#.NetVisual StudioVisual Studio-2012

C# Problem Overview


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?

C# Solutions


Solution 1 - C#

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 2 - C#

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 3 - C#

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

Solution 4 - C#

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.

Solution 5 - C#

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 6 - C#

I had this problem after resolving some conflicts from Subversion (SVN). The solution has several projects in it and I resolved some conflicts in a few different projects. I did a menu BuildClean Solution followed by a men BuildRebuild Solution and everything was good again.

Solution 7 - C#

Do you have any plugins installed, like ReSharper? I had an issues with a bad plugin.

Try running Visual Studio in safe mode, to prevent plugins from running.

devenv /Safemode

Solution 8 - C#

If you are using ReSharper like me, you may delete ReSharper cache following by this link: Configure Caches

To specify the location for caches:

  1. Open the Environment → General page of ReSharper options.
  2. Use the Save solution caches in to select the location for cache files:
  3. User local settings folder to store them in the following directory: %LOCALAPPDATA%\JetBrains\Transient 4.System TEMP folder to store them in the following directory: %TEMP%\ReSharperCache
  4. Solution folder to store them in the root folder of the current solution
  5. Custom folder to choose a custom location for ReSharper cache files.
  6. Click Save to apply the modifications and let ReSharper choose where to save them, or save the modifications to a specific settings layer using the Save To drop-down list. For more information, see managing and sharing ReSharper settings.
  7. Reopen your solution for the changes to take effect.

Solution 9 - C#

In Visual Studio 2013 I solved this problem by deleting all of my obj and bin folders across all projects. The issue was probably due to solution configurations that I had deleted, but I hadn't been cleaned up properly, as doing a menu BuildClean Solution doesn't remove the old outputs from the obj and bin folders.

Solution 10 - C#

What works for me is deleting the IntelliSense indexfile.

The IntelliSense-file is in the same directory as you solution.

It's filename is SolutionName.sdf

Just delete this file, open you solution again, and IntelliSense will start rebuilding its indexfile. After that the problem will be gone.

Solution 11 - C#

This worked for me in Visual Studio Enterprise 2017:

  1. Navigate to Tools > Options > Text Editor > JavaSCript/TypeScript > Linting > General

  2. deselect "Enable ESLint"

Solution 12 - C#

Steps that work

  1. Open the solution and do a rebuild all
  2. Close the solution
  3. Open solution and do a clean
  4. Close solution
  5. Open solution and do a rebuild all
  6. Close and then open the solution. It should be good. This works for me every time

Be careful deleting some of these settings files as you will lose saved debug settings, etc. And it may do more damage than you realize.

Solution 13 - C#

Simply refresh the project/solution. It will get resolved.

Solution 14 - C#

I've run into this as well and was able to return Visual Studio to its normal state by doing the following -

  1. Identify the project where the red lined code comes from
  2. Remove the "red line" project from the references where it is being used (ProjectName\References - right click, add references, and uncheck the "red line" project)
  3. Build (you should get errors now)
  4. Readd the project reference that was just removed
  5. Build again
  6. The red lines should be removed and the project should build!

Solution 15 - C#

I had the same problem with lots of red lines in several *cpp source files. Though the code compiled perfectly. None of the other solutions worked for me.

Changing the order of #include lines of a *.cpp-file could make the red lines disappear - and reappear with the restored order.

Then I noticed a header file was included twice in a single *.cpp file. I removed the second one and - everything was fine.

Including a header file twice in the same *.cpp file seems to be no problem to the compiler but to the IntelliSense part.

Solution 16 - C#

I have VS2019 with ReSharper, and ran into this issue.

What worked for me was:

  • Go to the ReSharper >> Options menu
  • Go to the General tab (should be the default)
  • Press the "Clear caches" button
  • Close all instances of Visual Studio (2019)
  • Restart Visual Studio

Solution 17 - C#

I had a similar problem when I was seeing lot of red squiggles in a couple of files. I tried all answers proposed previously, but nothing seemed to work.

The moment I started browsing through the classes, structures in other files for which complaining files had references, the problem disappeared. It seemed IntelliSense was not able to resolve dependencies on its own for some reason.

Solution 18 - C#

For me, I had at one time enabled fusion logging to debug some assembly dependency errors (fuslogvw from a CMD prompt). That was months ago and I had been experiencing much slower build times (5-7 minutes) since then.

I had also forgotten entirely that I had left them enabled. These logs were my bottleneck and disabling them has made iterating much faster.

Solution 19 - C#

I ran into this problem with the latest Visual Studio 2017.
Also the debug version of my program was running painfully slow.

I deleted the Solution file .sln and created a new one.

Solution 20 - C#

In my case with Visual Studio 2017, I have many "red lines" shown below all symbols defined in a third-party library, but my project can actually build without problems. I have tried all suggested solutions (like delete the .VS folder, restart Visual Studio, etc.), but none of them working.

Finally, I fixed it and this is how: I open my application project's property page, then go to C/C++GeneralAdditional Include Directories, which is the place I put all needed third-party library header paths.

I delete all the path (but save them somewhere), click "Ok" to confirm. Then I come back to the same setting, paste those paths back, click "Ok" to confirm, and then all those "red lines" disappear.

Solution 21 - C#

Found this solution:

  1. Close Visual Studio (ensure devenv.exe is not present in the Task Manager).
  2. Delete the %USERPROFILE%\AppData\Local\Microsoft\VisualStudio\xx\ComponentModelCache directory.
  3. Restart Visual Studio.

Solution 22 - C#

I have had this problem for months and have finally fixed it. Closing Visual Studio and removing the .vs folder located in the solution directory did not work for me.

There was an assemblyIdentity tag in the web.config file which was referencing a library that was not in my references folder. I removed this tag, cleaned, closed and reopened, and the problem was fixed.

  1. Check each of the assemblyIdentity tags in your web.config file and check them against the references folder in solution explorer
  2. Remove any assemblyIdentity tags, including the parent dependentAssembly tag for any which aren't listed in your references folder.
  3. Clean the solution
  4. Close and reopen the solution

Solution 23 - C#

Deleting .vs folder did the trick for me.

Solution 24 - C#

for me this works:-

  1. Open the Command Palette ctrl++p
  2. Then type: reload Window.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionLostView Question on Stackoverflow
Solution 1 - C#VeganHunterView Answer on Stackoverflow
Solution 2 - C#levelnisView Answer on Stackoverflow
Solution 3 - C#SkrView Answer on Stackoverflow
Solution 4 - C#Kevin BrydonView Answer on Stackoverflow
Solution 5 - C#samnericView Answer on Stackoverflow
Solution 6 - C#LUKEView Answer on Stackoverflow
Solution 7 - C#MarkoView Answer on Stackoverflow
Solution 8 - C#uzay95View Answer on Stackoverflow
Solution 9 - C#RocklanView Answer on Stackoverflow
Solution 10 - C#A.FranzenView Answer on Stackoverflow
Solution 11 - C#Gerald LeRoyView Answer on Stackoverflow
Solution 12 - C#Hamish RedmondView Answer on Stackoverflow
Solution 13 - C#S J KarthiView Answer on Stackoverflow
Solution 14 - C#Brian MikinskiView Answer on Stackoverflow
Solution 15 - C#hartwinView Answer on Stackoverflow
Solution 16 - C#Svein Terje GaupView Answer on Stackoverflow
Solution 17 - C#irsisView Answer on Stackoverflow
Solution 18 - C#TabrockView Answer on Stackoverflow
Solution 19 - C#juergen dView Answer on Stackoverflow
Solution 20 - C#Hongkun WangView Answer on Stackoverflow
Solution 21 - C#darrellhView Answer on Stackoverflow
Solution 22 - C#BenjoView Answer on Stackoverflow
Solution 23 - C#Wasif EhsanView Answer on Stackoverflow
Solution 24 - C#Ajay jangidView Answer on Stackoverflow