Visual Studio 2015 or 2017 shows IntelliSense errors but solution compiles
Asked Answered
R

12

137

We are currently evaluating the new Visual Studio 2015 and encountered a strange problem with IntelliSense. When I compiled our main solution with the new studio the build succeeds, but nevertheless 6 errors are shown.

I discovered that it's not a real error, but only an intellisense error. The code is definitely correct and everything compiled successfully. The code however is marked red and errors show up in the error list.

All 6 errors have the same origin. It's a simple constructor call. Strange enough, but there are also some occurrences of the exact same constructor without any errors.

The error message:

Code: CS1729
Message: '<the class>' does not contain a constructor that takes that many arguments.
Project: <the project name>
File: <the path to the file>

The new studio was installed on a freshly installed Windows 7 without any legacy software (no VS13).

I've already tried to clear the caches, deleted the suo file, deleted bin and obj directories, cleaned and rebuilt the solution etc. But nothing worked.

Can anyone explain that behavior to me?

Rhinitis answered 11/8, 2015 at 13:49 Comment(8)
The parser used by intellisense is not the same as the compiler used to actually compile the code.Picrotoxin
This happens on VS 2013 too. It could be that VS hasn't finished indexing the whole code base yet. If it compiles and work as expected, I won't pay any attention to it.Maureenmaureene
@Picrotoxin In VS2015 it should be the same parser, part of Roslyn.Chordate
Can you create a small project that reproduces the problem? If so, can you post the code?Chordate
Is the class partial, or is any part of it generated at compile time?Antipole
@LasseV.Karlsen: I've tried to create a sample project. But the issues don't occor there. Even within the big solution there are usages of the exact same constructor without any errors.Rhinitis
@PanagiotisKanavos: No it's not a partial class, but it's nested within a other class. Besides that it's absolutely normal.Rhinitis
I'm currently getting this but I'm doing crazy stuff with std::bind so I guess I deserve itTelegu
F
59

Also had this problem with a migrated project, so I referenced the Microsoft.CSharp dll. In some projects I needed to remove and add again the Reference in the project.

Flagellate answered 15/9, 2015 at 12:40 Comment(7)
I had to do this when a team member added a new project to the solution and migrated some cs files from an existing project to the new one. When I got latest, I saw many errors but I could compile and run. Dropping and re-adding the reference to the new project from the offended project worked for me.Zoi
Exactly the same situation that Bill described happened to us. Some classes were moved to a new project. It seems like Visual Studio didn't update it's Intellisense cache when new project reference was imported from the source control. Re-entering the reference manually forced VS to do so.Haemato
Solution compiles, but shows squiggly errors in some files. No errors where shown in "Release", just in Debug. Removed Microsoft.CSharp, and the errors are gone, thanks!Helminth
@Helminth Thanks for that tip. I have exactly the same issue. No errors in Release but a lot of errors in Debug.Jacquettajacquette
If the class mentioned is your own code, you can just exclude then include the file that contains the class. It should trigger VS to update IntelliSense. #awfulbugLed
Worth mentioning imo: I had this exact problem in VS 2017 with a Visual Basic Project. I had to add the CSharp Reference, recompiled and Intellisense errors were gone. After that I could remove the reference again.Virgule
If you have to remove and add the reference you could do it with any reference, I think. It seems to triger the rebuild of the .suo file. So deleting it is the better solution I think. Just more logical.Selectivity
I
217

I had thousands of intellisense errors and 0 build errors. After deleting .suo file and restarting VS intellisense errors are gone.

Suo file is located relatively to source in: .vs\SolutionName\v14\.suo

According to comment: Beware that *.suo is a hidden file.

Edit: According to comments, VS2017 has the same issue, so you can use similar solution: Delete .vs\SolutionName\v15\.suo

VS2019 still has this issue. Delete .vs\SolutionName\v17\.suo

If deleting .suo still does solve your problem, then delete also all bin and obj directories in every project in the solution.

Intuitive answered 2/11, 2015 at 12:30 Comment(9)
Just a note: *.suo files may be hidden in some cases. So you need to enable the View Hidden files option from windows explorer.Noelnoelani
Killing the .suo had no effect for me, but deleting the bin and obj dir and then rebuilding the solution did it.Electrolysis
Deleting the .suo file did not solve the problem for me (in VS2015) I am getting the spurious red squiggly in javascript that references properties from code-behind: <%=Foo%> saying the variable is not declared, but everything works at runtime.Arson
I'm not 100% sure, but this could also have fixed invalid markup errors I was getting with XAMLBandoline
find . -name "*suo" -exec rm -rf {} \;Shull
I had a similar issue due to Resharper which needed its cache cleared.Carmichael
Sorry to add a comment but I had same problem on vs 2017 (15.8.3 ), problem solved after delting .vs dir..Stedfast
@ErikSimonic Yes, VS 2017 is reflected in answer text also.Intuitive
Oddly enough, the problem still occurs with VS 2019 (v17.3.6). And this answer still applies.Pumpkinseed
F
59

Also had this problem with a migrated project, so I referenced the Microsoft.CSharp dll. In some projects I needed to remove and add again the Reference in the project.

Flagellate answered 15/9, 2015 at 12:40 Comment(7)
I had to do this when a team member added a new project to the solution and migrated some cs files from an existing project to the new one. When I got latest, I saw many errors but I could compile and run. Dropping and re-adding the reference to the new project from the offended project worked for me.Zoi
Exactly the same situation that Bill described happened to us. Some classes were moved to a new project. It seems like Visual Studio didn't update it's Intellisense cache when new project reference was imported from the source control. Re-entering the reference manually forced VS to do so.Haemato
Solution compiles, but shows squiggly errors in some files. No errors where shown in "Release", just in Debug. Removed Microsoft.CSharp, and the errors are gone, thanks!Helminth
@Helminth Thanks for that tip. I have exactly the same issue. No errors in Release but a lot of errors in Debug.Jacquettajacquette
If the class mentioned is your own code, you can just exclude then include the file that contains the class. It should trigger VS to update IntelliSense. #awfulbugLed
Worth mentioning imo: I had this exact problem in VS 2017 with a Visual Basic Project. I had to add the CSharp Reference, recompiled and Intellisense errors were gone. After that I could remove the reference again.Virgule
If you have to remove and add the reference you could do it with any reference, I think. It seems to triger the rebuild of the .suo file. So deleting it is the better solution I think. Just more logical.Selectivity
L
27

Ran into similar issue in Visual Studio 2017 ASP.Net Core Project. Following steps did the trick for me

  1. Perform Clean Solution
  2. Close VS
  3. Delete .suo file & Delete bin/obj directories
  4. Reopen VS
Lith answered 1/4, 2017 at 21:24 Comment(2)
This works but such a tedious thing to do time to time. I always have this problem when building in release mode. Strange VS cant figure it out by itself.Bucky
Deleting obj directory made the difference and got it to work(as bin was already empty).Toggle
C
13

Similar problem as others, but different resolution. Posting in case I can help someone else.

Running Visual Studio 2017 15.5.2. I use Git and frequently switch branches. Several weeks ago, I started having editors show me errors (all related to types it could not find even though references were valid). Compile worked great. I confirmed the same issue in VS 2017 15.6 Preview (Jan 6, 2018). I would try to delete cache, SUO files, or bin/obj folders and no impact. At first it would appear to work. Reopen Visual Studio and everything would look good. Use "Rebuild Solution" and the IntelliSense errors would returns. I even tried uninstall/reinstall of Visual Studio.

I had the same issue on two machines, both with same version of Visual Studio.

By looking at the errors about missing types, they all appeared to come from two referenced projects. One of those references was a shared project used by just about every other project in the solution, but one of them was a small project without many references. It just so happens that the small project was also referenced by my larger shared project. In Visual Studio, I unloaded the small project and reloaded it. The errors went away! They errors did not come back on Rebuild Solution.

I then switched Git branches and the errors all came back. Fortunately I repeated the above steps of unloading/reloading the small project and the errors went away.

Every time I switch Git branches, the errors come back until I repeat that process. There are zero changes between the Git branches for the smaller project that I unload/reload. Unclear why that sequence is fixing my issue.

Crysta answered 6/1, 2018 at 17:39 Comment(2)
Based off of this, I unloaded three "Test" or "Architecture" related projects, then unloaded and reloaded the Intellisense error-filled project (WPF). 0 of 0 errors :) +1 for the discrete details that led me to try something similar to you HgCoder!Thievery
Using VS 2017 15.9.9. Using Git. Using R#. I regularly switch branches as well. My errors are indeed all IntelliSense. I notice the unloading of the project causes the "Project" column (in the Error List tab) to go to <Unknown>. So, it does appear to be kicking it a bit. Unloading projects seems to have worked for me as well. A Clean Solution + Rebuild Solution finally yielded 0 errors.Pacien
F
7

Also had this problem (the title, not the specific error message), as well as squiggly lines in the editor. The first squiggly line is under the first #include statement, which names a precompiled header. Intellisense fails to include the precompiled header, but doesn't list that as an error; instead it lists errors further down the file, on code that (very rightfully) relies on declarations in the precompiled header.

The reason Intellisense doesn't find the precompiled header in my environment is that the header named is not an actual file. It doesn't have to be in any other VC or gcc version I used, nor in the 2015 compiler, as long as the precompiled header settings are correctly configured. Apparently not any more for Intellisense. I'm not entirely sure it was different in 2013, maybe I just never noticed.

In the unlikely case that this would be the problem reported here, the solution is simple: create a small file with the pretend-name of the precompiled header, as specified in #include directives, and let that file include the actual name of the precompiled header.

If you wonder... why this distinction between the precompiled header name in the '#include' statement and the actual filename of the precompiled header? Precisely because it guarantees that precompiled header settings are correctly configured. Wherever a precompiled header is "#included", there is no file around that could be included. Either an actually precompiled (binary) version of the actual header is read, or the compilation fails. Obviously, a disadvantage is that it confuses people reading the code, not just Intellisense.

Fiftyfifty answered 15/9, 2015 at 20:55 Comment(0)
S
2

Today I've had similar problem with MSVC++ 2015. I almost gave up and decided to go on without IDE hints, but suddenly I've noticed that stdafx.h of the project i had problems with doesn't contain any standard library headers. I've speculated that inclusion of all standard headers used in the project in stdafx.h might boost up compilation speed, however doing so fixed Intellisense errors as well.

Silverfish answered 22/1, 2017 at 19:40 Comment(0)
T
2

Visual Studio 2017 I have deleted ".suo" file from location .vs\SolutionName\v15.suo And then restarted Visual studio. This worked for me.

Tertiary answered 10/9, 2018 at 14:46 Comment(0)
B
2

In Visual Studio 2019 the problem is with changing branches with Git when there are NuGet packages installed in the project. What I did to solve this:

  1. Clean Solution
  2. Close Visual Studio
  3. Delete the packages folder
  4. Open Visual Studio
  5. Go to Package Manager
  6. Restore all packages
  7. Recompile
  8. If roslyn is missing, close and open Visual Studio, then recompile.
Branum answered 16/3, 2020 at 15:28 Comment(0)
S
1

I had multiple stdfax.h in Additional Include Directories. Make sure the stdafx.h you intended is first in your path.

Stuck answered 30/5, 2017 at 14:56 Comment(0)
N
1

I had a similar issue with different Visual Studio versions.

Deleting the .suo or .vs folder did not help for me.

The Solution for me was, that I had the Extension StopOnFirstBuildError active. After turning off "Stop build on first error" in the build menu, and after the solution was fully built, the errors shown by Intellisense went away.

Noahnoak answered 13/3, 2018 at 7:34 Comment(0)
M
1

I was seeing the intellisearch errors only when publishing a website. (ASP/C# site, VS 2017). They broke the publish. Site ran fine locally.

Cleared the errors by unchecking the setting to pre-compile, and it published fine. Publish -> Setting -> File Publish Options -> Precompile during publishing

Mahound answered 10/5, 2018 at 18:2 Comment(0)
S
0

I had this issue with a reference to another project. Removing and re-adding the project reference worked for me.

Salazar answered 8/10, 2021 at 18:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.