Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio Shows code errors that don't exist

I'm not sure if anyone else has encountered this but often, when I open this particular solution, I see a whole list of errors (see below).

Error Image

If I double click one of them, then Visual Studio seems to wake up and the errors relating to that particular cs file disappear. This isn't a critical issue and is more on an irritation than anything else but I wonder, is there perhaps something wrong with my code that's causing this false-positive or is it random Visual Studio behaviour?

like image 653
Daniel Avatar asked May 18 '17 10:05

Daniel


3 Answers

I had this problem too. Deleting bin and obj folders not work. Cleaning solution not work. Various platform I need to be as is.

Helped me close solution and delete folder .vs, which is often full of problematic mess. After opening solution all false errors disappeared.

like image 55
bmi Avatar answered Oct 03 '22 00:10

bmi


As mentioned in a comment, you can do a Clean and Rebuild. If that does not work for you, you can browse to the solution folder and within each of the project folders delete the bin and obj folders. Then perform a build.

You may also want to look into your Configuration Manager and ensure that all of your projects are set to the same Configuration (Debug/Release) and Platform (Any CPU/x86/etc...) and marked to build for that configuration.

Finally, you may also want to check the Build Order for your solution. Ensure that projects are all built in the proper order.

-- Edit:

On thing brought up in comments that I will add here was to make sure that any library projects in the solution are added as Project References rather than referencing the output DLL directly.

like image 22
gmiley Avatar answered Oct 02 '22 22:10

gmiley


Something that has only become evident in later years, and is only relevant upon reflection on this old question, is that the particular solution that we experience this issue in contains a Website project and NOT a WebApplication project. This became evident when we started to look deeper into these recurring errors and noted that they only ever related to codebehind files and all had to do with the Control Name not existing in the current context.

Amongst the various differences between the two project types, it seems that the lack of designer files for each ASP page may be a contributing factor. The error disappears as soon as you double click it potentially indicating that VS is not able to keep track of the control references until you open the relevant page / codebehind file.

We're moving over to a Web Application as a temporary measure.

Hope this insight helps someone else!

like image 32
Daniel Avatar answered Oct 03 '22 00:10

Daniel