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

The best answers to the question “Getting "type or namespace name could not be found" but everything seems ok?” in the category Dev.


I’m getting a:

type or namespace name could not be found

error for a C# WPF app in VS2010. This area of code was compiling fine, but suddenly I’m getting this error. I’ve tried removing the Project Reference and the using statement, shutting VS2010 and restarting, but still I have this issue.

Any ideas why this might be occurring, where it seems like I’m doing the right thing re Reference & using statement?

I also noted in VS2010 that intellisense for that namespace is working ok, so it seems like VS2010 has the project reference and is seeing the namespace on one hand, but during compile doesn’t see it?


Reinstalling nuget packages did the trick for me. After I changed .NET Framework versions to be in sync for all projects, some of the nuget packages (especially Entity Framework) were still installed for previous versions. This command in Packages Manager Console reinstalls packages for the whole solution:

Update-Package –reinstall


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)


When building the solution I was getting the same error (type or namespace ‘ ‘ could not be found). Below it I saw a warning stating that “the reference could not be resolved” and to make sure “the assembly exists on disk”.

I was very confused, because my DLL was very clearly in the location that the reference was pointing to. VS didn’t seem to highlight any errors, until I tried to build the solution.

I finally realized the problem (or at least what I suspect was the problem). I was building the library file in the same solution. So even though it existed on the disk, it was being rebuilt in that location (somehow in the process of the library getting rebuilt my other project – in the same solution – that referenced the library must have decided that the library didn’t exist)

When I right-clicked on the project and built that only, instead of the entire solution, I didn’t get the error.

To fix this problem I added the library as a dependency to the project that was using it.

To do this:

  1. I right-clicked on my Solution in the Solution Explorer and selected
  2. Then in “Common Properties” I selected “Project Dependencies”.
  3. Then in the Projects drop-down menu I selected the project that
    relied on the library, and
  4. Checked the box next to the library found under “Depends On”

This ensures that the library project gets built first.


I’ve no idea why this worked, but I removed the project reference that VS2015 was telling me it couldn’t find, and added it again. Solved the problem. I’d tried both cleaning, building and restarting VS to no avail.