Shaul Behr
Shaul Behr

Reputation: 38003

Why does ASP.NET refuse to recognize the namespace of a related project?

I have a ASP.NET MVC 2 project, which references several other projects in my solution. In the C# code, all references work fine, but in the ASP.NET code things go awry - one of the referenced namespaces is not recognized. I put in my Web.config file:

<pages>
  <namespaces>
    <add namespace="System.Web.Mvc" />
    <add namespace="System.Web.Mvc.Ajax" />
    <add namespace="System.Web.Mvc.Html" />
    <add namespace="System.Web.Routing" />
    <add namespace="Project1"/>
    <add namespace="Project2"/>
  </namespaces>
</pages>

And as soon as I open the project, I get a crash screen with the message:

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

I cannot see anything qualitatively different between Project1 and Project2, yet the one's namespace is accepted as a valid while the other's isn't. I have explicitly added references to System.Data.Entity as well; that doesn't seem to help.

Any ideas?

Upvotes: 0

Views: 1591

Answers (3)

MLewi
MLewi

Reputation: 261

List of things that can be wrong can be found on : http://support.microsoft.com/kb/304656

Short summary

  • You might have misspelled the name of the type or namespace that you are trying to use.
  • correct capitalization
  • If the error is a reference to a namespace, you may not have the assembly where the namespace is located referenced in your project.
  • If the error is a reference to a type, then you may not have the proper using directive, or you may have not fully qualified the name of the type.

You can also check root namespaces.

Upvotes: 2

cusimar9
cusimar9

Reputation: 5259

Have you added a reference to Project2?

Upvotes: 0

Nathan
Nathan

Reputation: 6216

That config specifies that the project's namespace should be included in all your pages (equivalent to putting a using statement in all your pages).

It doesn't however add a reference to the project - you probably need to add a reference to one of your other projects. (Project2)

Upvotes: 0

Related Questions