简体   繁体   English

尝试使用类时发生错误,提示找不到类型或名称空间

[英]Error when trying to use class, says that the type or namespace cannot be found

I've looked at many questions about this issue and most fixed by changing the applications target from Net 4.0 Client to just Net 4.0, mine is already like that, so that is not the issue. 我已经看过许多有关此问题的问题,并且通过将应用程序目标从Net 4.0 Client更改为Net 4.0来解决了大多数问题,我的问题已经解决了,所以这不是问题。 The situation is I just got Json.Net and I created a class, Customer, to use with it, the following: 情况是,我刚得到Json.Net,并创建了一个与客户一起使用的类Customer:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace CC
{
    public class Customer
    {
        private string location;

        public string Location
        {
            get { return location; }
            set { location = value; }
        }

        private string name;

        public string Name
        {
            get { return name; }
            set { name = value; }
        }

        private int serviceTimeMin;

        public int ServiceTimeMin
        {
            get { return serviceTimeMin; }
            set { serviceTimeMin = value; }
        }

        public Customer()
        {
        }
    }
}

and then within my pages codebehind I have the following code: 然后在我的页面代码中,我有以下代码:

protected void Button_Click(object sender, EventArgs e)
        {
            Customer customer = new Customer();
            customer.Location = txtCustomerAddress + ", " + txtCustomerCity + ", " + txtCustomerState + " " + txtCustomerZipcode;
            customer.Name = txtCustomerFirstName + " " + txtCustomerLastName;
            customer.ServiceTimeMin = 3;
            string json = JsonConvert.SerializeObject(customer);
         }

It is in the same namespace and all, already checked that, and when I type it out it has no error, it's just when I build to debug that I get the following: 它在同一个名称空间中,并且已经检查过所有名称,当我键入它时没有错误,只是在进行调试时得到以下信息:

CS0246: The type or namespace name 'Customer' could not be found (are you missing a using directive or an assembly reference?)

and the source points to the line: 源指向该行:

Line 290:            Customer customer = new Customer();

What am I missing? 我想念什么?

EDIT: Just want to clarify, this is all in the same namespace and same project (assembly). 编辑:只是想澄清一下,这都是在相同的名称空间和相同的项目(程序集)中。

Is the codebehind also in the CC namespace? 隐藏在CC命名空间中的代码也是吗? Otherwise you need to add using CC to the top of the file. 否则,您需要using CC添加到文件顶部。

The only other thing I can think of is, if Customer did not build correctly. 我唯一能想到的是,如果Customer构建不正确。 Are there any other errors or warnings? 还有其他错误或警告吗? This may be a side-effect error. 这可能是一个副作用错误。

Are you running tests, and do you have code coverage enabled? 您是否正在运行测试,并且已启用代码覆盖率? Sometimes when this is the case your project DLL will not be updated. 有时在这种情况下,您的项目DLL将不会被更新。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么我收到错误 CS0246:尝试使用 OpenHtmlToPdf 时找不到类型或命名空间名称? - Why am I getting error CS0246: The type or namespace name could not be found when trying to use OpenHtmlToPdf? 尝试编译时找不到命名空间错误 - Namespace not found error when trying to compile 我最近在类库中添加了一个文件夹,现在出现错误“找不到类型或名称空间” - I recently added a folder to my class library, now I get an error “the type or namespace cannot be found” 错误:找不到类型或名称空间 - Error: Type or namespace not found 无法找到类型或命名空间User - The type or namespace User cannot be found 找不到类型或名称空间窗口 - Type or namespace Window cannot be found 当引用确实存在时,找不到类型或命名空间 - Type or namespace cannot be found, when reference does exist 尝试添加相机更改组件时出现错误“找不到脚本 class” - Error `script class cannot be found` when trying to add a camera change component NancyFx 测试:找不到类型或命名空间 Bootstrapper - NancyFx testing: The type or namespace Bootstrapper cannot be found Topshelf - 类型或命名空间名称 Topshelf 找不到 - Topshelf - Type or namespace name Topshelf cannot be found
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM