rjg132234
rjg132234

Reputation: 620

"The type or namespace name could not be found" when publishing ASP .NET MVC Project

I am new to C# ASP .NET MVC so I am not sure about a lot of things. But I inherited this project at my new company, and I am just trying to build the files that I had stored on the computer that I took over when I started here. I am pretty sure no one has touched these files since the last guy left, so I assume there should be no issues with the code, because the site is up live right now and working.

But when I try to publish these files to the staging site (for testing purposes) I get a bunch of the same errors (took out the full path given in the error) and the project fails to publish.

    Error   77  The type or namespace name 'Controller' could not be found (are you missing a using directive or an assembly reference?)    \Controllers\AccountController.cs   15  38  Project
Error   99  The type or namespace name 'HttpGetAttribute' could not be found (are you missing a using directive or an assembly reference?)  \Controllers\AccountController.cs   17  10  Project
Error   100 The type or namespace name 'HttpGet' could not be found (are you missing a using directive or an assembly reference?)   \Controllers\AccountController.cs   17  10  Project
Error   115 The type or namespace name 'ActionResult' could not be found (are you missing a using directive or an assembly reference?)  \Controllers\AccountController.cs   18  16  Project
Error   182 The type or namespace name 'HttpPostAttribute' could not be found (are you missing a using directive or an assembly reference?) \Controllers\AccountController.cs   40  10  Project
Error   183 The type or namespace name 'HttpPost' could not be found (are you missing a using directive or an assembly reference?)  \Controllers\AccountController.cs   40  10  Project
Error   186 The type or namespace name 'ActionResult' could not be found (are you missing a using directive or an assembly reference?)  \Controllers\AccountController.cs   41  16  Project
Error   257 The type or namespace name 'HttpGetAttribute' could not be found (are you missing a using directive or an assembly reference?)  \Controllers\AccountController.cs   78  10  Project
Error   258 The type or namespace name 'HttpGet' could not be found (are you missing a using directive or an assembly reference?)   \Controllers\AccountController.cs   78  10  Project
Error   265 The type or namespace name 'ActionResult' could not be found (are you missing a using directive or an assembly reference?)  \Controllers\AccountController.cs   79  16  Project
Error   284 The type or namespace name 'HttpPostAttribute' could not be found (are you missing a using directive or an assembly reference?) \Controllers\AccountController.cs   89  10  Project
Error   285 The type or namespace name 'HttpPost' could not be found (are you missing a using directive or an assembly reference?)  \Controllers\AccountController.cs   89  10  Project
Error   291 The type or namespace name 'ActionResult' could not be found (are you missing a using directive or an assembly reference?)  \Controllers\AccountController.cs   90  16  Project
Error   332 The type or namespace name 'AuthorizeAttribute' could not be found (are you missing a using directive or an assembly reference?)    \Controllers\AccountController.cs   112 10  Project
Error   333 The type or namespace name 'Authorize' could not be found (are you missing a using directive or an assembly reference?) \Controllers\AccountController.cs   112 10  Project
Error   335 The type or namespace name 'ActionResult' could not be found (are you missing a using directive or an assembly reference?)  \Controllers\AccountController.cs   113 16  Project
Error   343 The type or namespace name 'AuthorizeAttribute' could not be found (are you missing a using directive or an assembly reference?)    \Controllers\AccountController.cs   121 10  Project
Error   344 The type or namespace name 'Authorize' could not be found (are you missing a using directive or an assembly reference?) \Controllers\AccountController.cs   121 10  Project
Error   345 The type or namespace name 'ActionResult' could not be found (are you missing a using directive or an assembly reference?)  \Controllers\AccountController.cs   122 16  Project
Error   363 The type or namespace name 'HttpGetAttribute' could not be found (are you missing a using directive or an assembly reference?)  \Controllers\AccountController.cs   150 10  Project
Error   364 The type or namespace name 'HttpGet' could not be found (are you missing a using directive or an assembly reference?)   \Controllers\AccountController.cs   150 10  Project
Error   365 The type or namespace name 'AuthorizeAttribute' could not be found (are you missing a using directive or an assembly reference?)    \Controllers\AccountController.cs   151 10  Project
Error   366 The type or namespace name 'Authorize' could not be found (are you missing a using directive or an assembly reference?) \Controllers\AccountController.cs   151 10  Project
Error   367 The type or namespace name 'ActionResult' could not be found (are you missing a using directive or an assembly reference?)  \Controllers\AccountController.cs   152 16  Project
Error   377 The type or namespace name 'HttpGetAttribute' could not be found (are you missing a using directive or an assembly reference?)  \Controllers\AccountController.cs   162 10  Project
Error   378 The type or namespace name 'HttpGet' could not be found (are you missing a using directive or an assembly reference?)   \Controllers\AccountController.cs   162 10  Project
Error   379 The type or namespace name 'AuthorizeAttribute' could not be found (are you missing a using directive or an assembly reference?)    \Controllers\AccountController.cs   163 10  Project
Error   380 The type or namespace name 'Authorize' could not be found (are you missing a using directive or an assembly reference?) \Controllers\AccountController.cs   163 10  Project
Error   384 The type or namespace name 'ActionNameAttribute' could not be found (are you missing a using directive or an assembly reference?)   \Controllers\AccountController.cs   164 10  Project
Error   385 The type or namespace name 'ActionName' could not be found (are you missing a using directive or an assembly reference?)    \Controllers\AccountController.cs   164 10  Project

There are a bunch more of the same kind of errors for a lot of files in the project. The way the errors are showing, makes me believe it's an easy one off fix, because they are all the same error pretty much.

Anyone know how to fix these errors so I can successfully build this project?

Upvotes: 2

Views: 38939

Answers (4)

icStatic
icStatic

Reputation: 267

I had this issue. I tried all the answers above. The thing that finally fixed it was to close and reopen the solution.

Upvotes: 1

Inspector Squirrel
Inspector Squirrel

Reputation: 2548

You need to make sure that your project has references to all the required namespaces. For example, HttpGetAttribute and all the others in that list actually belong to System.Web.Mvc.

If you open up the references 'folder' in VS for that project, you'll probably see warning signs next to some of the references. Delete them and re-add them.

To re-add a reference, first delete it, then right click on the References folder, then click Add Reference. Click the Assembles treeview item on the left, then in the search box on the right hand side type in System.Web.Mvc and it'll bring up a list of versions of that DLL.

For future reference, whenever you see something like this, the best way to solve it is to just search the name of the class that can't be found followed by 'MSDN', in your case you'd search 'HttpGetAttribute msdn'. This will tell you which reference you need to include for it.

Upvotes: 8

SlimSim
SlimSim

Reputation: 616

The problem is most likely due to nuget packages not being restored. If your team is not checking nuget packages into source control, you will need to right click on the solution in solution explorer and select 'Enable Nuget Package Restore' and then rebuild the solution.

Upvotes: 1

MeanGreen
MeanGreen

Reputation: 3315

First make sure the base projects (without any references to other projects) build ok. If not, check the References folder in the project tree. If any icons have warnings, your reference to a library is invalid.

Then go from the base project to projects referring to the base one, and keep going until the entire solution is building ok again.

Upvotes: 3

Related Questions