The name 'username' does not exist in the current context when compiling as x64 RRS feed

  • Question

  • I have an ASP.NET web application with the following in the aspx page

    <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
            var username = "<%=username%>";


    The code behind sets up the variable username for example:

    public string username = "david";

    In Visual Studio error list pane, it shows this error "The name 'username' does not exist in the current context"

    So basically any page that I use <%=VARIABLE%> then I get this error.  But it compiles fine and works as expected.  But this error is really annoying when I have other pages with several of these errors.  This only happens when I build the project as x64.  It works fine if I do it in x86, but my other project in same solution must be x64 and referenced by my web app so everything needs to be x64 or it complains.  So why is it that Visual Studio complains about this error incorrectly when it compiles just fine?  What can I do to fix this?  Is this a bug I need to report to Visual Studio team?

    Wednesday, February 28, 2018 5:07 PM

All replies

  • According to the error, I wonder if you are using the right namespace in aspx page, which should be the same namespace as your code behind page. Please have a check, this issue is more related to Web development, you could post your issue in ASP.NET particular forum where you will get more professional support.

    And which version of Visual Studio are you using? The latest one is VS2017 15.5.7, please update it and see. If it still happens then it might be a really limitation.




    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Edited by Fletch Zhou Thursday, March 1, 2018 8:19 AM
    Thursday, March 1, 2018 8:19 AM
  • I wish it was that simple but if I switch the build to x86 then it doesn't show the error.  Either way it compiles fine, it's just the error message is annoying when I'm trying to fix real errors.

    I'll post on the ASP.NET forum.  Thanks

    Thursday, March 1, 2018 2:54 PM