Name does not exist in the current context

前端 未结 11 1650
时光说笑
时光说笑 2020-12-05 12:34

So, I\'m working on this project between my laptop and my desktop.

The project works on the laptop, but now having copied the updated source code onto the desktop, I

相关标签:
11条回答
  • 2020-12-05 13:12

    I solved mine by using an Import directive under my Page directive. You may also want to add the namespace to your Inherits attribute of your Page directive.

    Since it appears that your default namespace is "stman.Members", try: <%@ Page Title="" Language="C#" MasterPageFile="~/Members/Members.master" AutoEventWireup="true" CodeFile="Jobs.aspx.cs" Inherits="stman.Members.Members_Jobs" %> <%@ Import Namespace="stman.Members"%>

    Additionally, data that I wanted to pass between aspx.cs and aspx, I put inside a static class inside the namespace. That static class was available to move data around in the name space and no longer has a "not in context" error.

    0 讨论(0)
  • 2020-12-05 13:19

    In our case, beside changing ToolsVersion from 14.0 to 15.0 on .csproj projet file, as stated by Dominik Litschauer, we also had to install an updated version of MSBuild, since compilation is being triggered by a Jenkins job. After installing Build Tools for Visual Studio 2019, we had got MsBuild version 16.0 and all new C# features compiled ok.

    0 讨论(0)
  • 2020-12-05 13:20

    I also faced a similar issue, the problem was the form was inside a folder and the file .aspx.designer.cs I had the namespace referencing specifically to that directory; which caused the error to appear in several components:

    El nombre no existe en el contexto actual

    This in your case, a possible solution is to leave the namespace line of the Members_Jobs.aspx.designer.cs file specified globally, ie change this

    namespace stman.Members {

    For this

    namespace stman {

    It's what helped me solve the problem.

    I hope to be helpful

    0 讨论(0)
  • 2020-12-05 13:24

    "The project works on the laptop, but now having copied the updated source code onto the desktop ..."

    I did something similar, creating two versions of a project and copying files between them. It gave me the same error.

    My solution was to go into the project file, where I discovered that what had looked like this:

    <Compile Include="App_Code\Common\Pair.cs" />
    <Compile Include="App_Code\Common\QueryCommand.cs" />
    

    Now looked like this:

    <Content Include="App_Code\Common\Pair.cs">
      <SubType>Code</SubType>
    </Content>
    <Content Include="App_Code\Common\QueryCommand.cs">
      <SubType>Code</SubType>
    </Content>
    

    When I changed them back, Visual Studio was happy again.

    0 讨论(0)
  • 2020-12-05 13:26

    I had this problem in my main project when I referenced a dll file.

    The problem was that the main project that referenced the dll was targeting a lower framework version than that of the dll.

    So I upped my target framework version (Right-click project -> Application -> Target framework) and the error disappeared.

    0 讨论(0)
  • 2020-12-05 13:27

    Jobs.aspx

    This is the phyiscal file -> CodeFile="Jobs.aspx.cs"

    This is the class which handles the events of the page -> Inherits="Members_Jobs"

    Jobs.aspx.cs

    This is the partial class which manages the page events -> public partial class Members_Jobs : System.Web.UI.Page

    The other part of the partial class should be -> public partial class Members_Jobs this is usually the designer file.

    you dont need to have partial classes and could declare your controls all in 1 class and not have a designer file.

    EDIT 27/09/2013 11:37

    if you are still having issues with this I would do as Bharadwaj suggested and delete the designer file. You can then right-click on the page, in the solution explorer, and there is an option, something like "Convert to Web Application", which will regenerate your designer file

    0 讨论(0)
提交回复
热议问题