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\'
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();
}
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();
}
}
namespace TestApplication // Remove .Controller
{
public class HomeController : Controller
{
public ActionResult Index()
{
return View();
}
}
}
Remove the controller word from namepsace
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)
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
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.