Visual Studio 2010 Suddenly Can't See Namespace

Visual Studio 2010 suddenly can't see namespace?

I'm ready to declare this a bug in VS2010, this has bitten way too many programmers already. The fix is easy: Project + Properties, Application tab, change Target Framework to ".NET Framework 4" instead of the Client Profile that is selected by default.

System.Web is not included in the client profile. Having this option in the first place is quite silly, the client profile is only 15% smaller than the full version of .NET 4.0. Having it selected by default is even sillier. But I digress.

UPDATE: mercifully this all got fixed in VS2012. Which no longer makes the client profile the default for a new project. And the client profile got retired completely in .NET 4.5, good riddance.

Getting type or namespace name could not be found but everything seems ok?

This can be the result of a .Net framework version incompatibility between two projects.

It can happen in two ways:

  1. a client profile project referencing a full framework project; or
  2. an older framework version targeting a newer framework version

For example it will happen when an application is set to target the .Net 4 Client Profile framework, and the project it references targets the full .Net 4 framework.

So to make that clearer:

  • Project A targets the Client Profile framework
  • Project A references Project B
  • Project B targets the full framework

The solution in this case is to either upgrade the framework target of the application (Project A), or downgrade the target of referenced assembly (Project B). It is okay for a full framework app to reference/consume a client profile framework assembly, but not the other way round (client profile cannot reference full framework targeted assembly).

Note that you can also get this error when you create a new project in VS2012 or VS2013 (which uses .Net 4.5 as the default framework) and:

  • the referencing project(s) use .Net 4.0 (this is common when you have migrated from VS2010 to VS2012 or VS2013 and you then add a new project)

  • the referenced projects use a greater version i.e. 4.5.1 or 4.5.3 (you've re-targeted your existing projects to the latest version, but VS still creates new projects targeting v4.5, and you then reference those older projects from the new project)

Visual Studio 2010 add project reference then compiler says namespace could not be found

Check both project Target Framework, Are both same or not.

The issue can be that your are referencing a higher Target Framework project into a less Target Framework project.

Like If you have a project with Target Framework .Net Framework 4 and you are referencing it into a project with .Net Framework 4 Client Profile or .Net Framework 3.5, you will get the issue.

Namespace not recognized (even though it is there)

Check to make sure that your project isn't set up to use the .NET Framework 4 Client Profile.

You can check/change this by right-clicking your project (not the solution), select Properties -> Application -> Target framework. The target framework is a dropdown on that page.

This is a problem in Visual Studio (I would even go so far as to call it a bug). AutoMapper requires assemblies that are excluded from the .NET Framework 4 Client Profile. Since your project is using that version of the framework it breaks.

A similar error will propagate to the build process when the .NET Framework version for the project you are referencing is higher than the project making the reference. i.e. A project targeting 4.5 that references a project targeting 4.5.1 will give you this same error.

There needs to be a better error message when this happens because there is no rational explanation as to why it would not build as the error message tells you to reference an assembly you have clearly referenced.

I can't see a referenced class of another namespace in C#

Does the project contain a reference to the other project? You can't just add the namespace, the project itself needs an assembly reference to the other project which has that namespace.

In Visual Studio, open the Solution Explorer. Right-click on the ConstrainedSchedule project and select something along the lines of "Add Reference." In the dialog, select project references (depending on the version of Visual Studio it may be a tab or some other interface indicating projects as part of the solution). Select the ConstrainedScheduleInterfaces project and add the reference.

More information here.

Namespace not recognised in using statement. The type or namespace '#' does not exist in the namespace '#'. Are you missing an assembly reference?

OK, so I came up with a solution.

I thought I would try removing and recreating the references, and in a nutshell, this worked. Detail:

I right clicked on Argus.Web in the solution explorer, and then Build Dependencies > Project Dependencies. I tried deselecting Argus.Domain.Office.Command, but got the error 'This dependency was added by the project system and cannot be removed'. I'm not sure why this error appears, but I therefore tried right clicking on the references in Argus.Web, and selected 'Add Reference'. In the Projects section of the window that came up I was able to deselect Argus.Domain.Office.Command, so I did this, commented out the problematic using directive, cleaned and rebuilt my solution, added the reference back (right clicking on the references in Argus.Web, and selecting 'Add Reference'), and it all works again.

I guess that the original references must have been misconfigured, but at present I can't see how this came about. I will add to this post if I work out how this happened.

Many thanks to all respondees, all comments and answers were useful.



Related Topics



Leave a reply



Submit