Search code examples
c#visual-studio-2015

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


Solution

  • 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!