Daniel
Daniel

Reputation: 2295

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?

EDIT 2024: I see people are still experiencing this issue and wanted to share an update. I have overcome this by migrating / upgrading to a Web Application which seems to have resolved these issues. If that's not relevant to your issue, cleaning the solution and rebuilding may be your best option

Upvotes: 17

Views: 22103

Answers (3)

Daniel
Daniel

Reputation: 2295

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.

EDIT: We upgraded the website project to a Web Application project which has resolved these issues.

Hope this insight helps someone else!

Upvotes: 1

bmi
bmi

Reputation: 811

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.

Upvotes: 33

gmiley
gmiley

Reputation: 6604

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.

Upvotes: 10

Related Questions