'namespace' but is used like a 'type'

前端 未结 7 1529
孤独总比滥情好
孤独总比滥情好 2020-11-27 04:35

This is my program the class uses it is called Time2 I have the reference added to TimeTest I keep getting the Error \'Time2\' is a \'namespace\' but is used like a \'type\'

相关标签:
7条回答
  • 2020-11-27 05:18

    If you're working on a big app and can't change any names, you can type a . to select the type you want from the namespace:

    namespace Company.Core.Context{
      public partial class Context : Database Context {
        ...
      }
    }
    ...
    
    using Company.Core.Context;
    someFunction(){
     var c = new Context.Context();
    }
    
    0 讨论(0)
  • 2020-11-27 05:24

    Please check that your class and namespace name is the same...

    It happens when the namespace and class name are the same. do one thing write the full name of the namespace when you want to use the namespace.

    using Student.Models.Db;
    
    namespace Student.Controllers
    {
        public class HomeController : Controller
        {
            // GET: Home
            public ActionResult Index()
            {
                List<Student> student = null;
                return View();
            }
        }
    
    0 讨论(0)
  • 2020-11-27 05:26
    namespace TestApplication // Remove .Controller
    {
        public class HomeController : Controller
        {
           public ActionResult Index()
            {
                return View();
            }
        }
    }
    

    Remove the controller word from namepsace

    0 讨论(0)
  • 2020-11-27 05:27

    if the error is

    Line 26:
    Line 27: @foreach (Customers customer in Model) Line 28: { Line 29:

    give the full name space
    like @foreach (Start.Models.customer customer in Model)

    0 讨论(0)
  • 2020-11-27 05:32

    All the answers indicate the cause, but sometimes the bigger problem is identifying all the places that define an improper namespace. With tools like Resharper that automatically adjust the namespace using the folder structure, it is rather easy to encounter this issue.

    You can get all the lines that create the issue by searching in project / solution using the following regex:

    namespace .+\.TheNameUsedAsBothNamespaceAndType
    
    0 讨论(0)
  • 2020-11-27 05:35

    I had this problem as I created a class "Response.cs" inside a folder named "Response". So VS was catching the new Response () as Folder/namespace.

    So I changed the class name to StatusResponse.cs and called new StatusResponse().This solved the issue.

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