Coder Perfect

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


I’m getting a:

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 thoughts why this is happening when it appears that I’m using the correct reference and using statement?

I also noticed that intellisense for that namespace works fine in VS2010, so it appears that VS2010 has the project reference and sees the namespace on one hand, but doesn’t see it during compile?

Asked by Greg

Solution #1

This could be the result of two projects using different versions of the.Net framework.

It can occur in one of two ways:

When an application is set to target the, for example, this will occur. The framework for Net 4 Client Profiles, as well as the project it refers to, are both aimed at the whole. Framework based on.NET 4.

So, to be more specific:

In this scenario, the answer is to either upgrade the application’s framework target (Project A) or downgrade the referenced assembly’s goal (Project B). It’s fine for a full framework program to reference/consume a client profile framework assembly, but not vice versa (client profile cannot reference full framework targeted assembly).

This problem can also occur if you create a new project with Visual Studio 2012 or 2013 (which uses.Net 4.5 as the default framework) and:

Answered by slugster

Solution #2

I was able to resolve the issue by reinstalling nuget packages. Some of the nuget packages (particularly Entity Framework) were remained installed for older versions after I adjusted the.NET Framework versions for all projects to be in sync. This command in Packages Manager Console reinstalls packages for the whole solution:

Update-Package –reinstall

Answered by saxorut

Solution #3

I’m not sure why this worked, but I removed and re-added the project reference that VS2015 said it couldn’t find. I was able to solve the issue. To no effect, I tried cleaning, building, and restarting Visual Studio.

Answered by Alexander Høst

Solution #4

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 grasped what was wrong (or at least what I suspect was the problem). In the same solution, I was creating the library file. 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)

I didn’t get the issue when I right-clicked on the project and constructed it separately from the rest of the solution.

To resolve the issue, I added the library as a dependency to the project that used it.

To do this:

This guarantees that the library project will be completed first.

Answered by ksun

Solution #5

First, I’d double-check that the data generated by your project isn’t corrupt. Cleaning and rebuilding your solution is a good idea.

If that doesn’t work, I’ve seen opening a windows forms project and then closing it work in the past for designer issues. Don’t hold your breath, though; this is a little chicken-entrails-ish.

Answered by Greg D

Post is based on