Search code examples
c#asp.netcompiler-errorsvisual-studio-2019build-error

(Potential Visual Studio Bug) Visual Studio 2019 Error List showing errors that should not exist as that error isn't actually present


This is for an ASP.NET Webforms project.

On the .ASPX file there is a :

<span id="FooterTextSpan" runat="server">[Redacted]</span>

I am editing the span from the code-behind (ASPX.cs file), and in Visual Studio, I see this:

The name 'FooterTextSpan' does not exist in the current context

And yet, it is there in the .ASPX file.

In the @Page... declaration the correct CodeBehind is specified, and it Inherits from the correct location, too.

The project does not build if you try to build and don't do the 'hacky-fix' below:

To fix this, you can go into the .ASPX page, and add a space, then delete the space, and the error just vanishes.

How do I resolve this so I do not need to do this 'hacky-fix', as it is happening in other files, too.


Solution

  • Sanguine,

    I have met this IntelliSense misreport problem for few times and it is really annoying. Fortunately, it is rare.

    If you have tried

    1. clean and rebuild the solution or
    2. delete the .vs folder to clean the cache
      and the problem is still there, here is a workaround.

    As you can see in VS, there are few of options for selection in the "Error list" section.

    enter image description here

    You can select "Build Only" so that the error list only shows the error from build.

    Hope this can help you.