Getting "type or namespace name could not be found" but everything seems ok?
Solution 1
This can be the result of a .Net framework version incompatibility between two projects.
It can happen in two ways:
- a client profile project referencing a full framework project; or
- 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)
Solution 2
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
Solution 3
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.
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 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:
- I right-clicked on my Solution in the Solution Explorer and selected "Properties"
- Then in "Common Properties" I selected "Project Dependencies".
- Then in the Projects drop-down menu I selected the project that relied on the library, and
- Checked the box next to the library found under "Depends On"
This ensures that the library project gets built first.
Solution 5
First I would verify that your project's generated information isn't corrupt. Do a clean and rebuild on your solution.
If that doesn't help, one thing I've seen work in the past for designer issues is opening up a windows forms project, then closing it again. This is a little chicken-entrails-ish, though, so don't hold your breath.
Related videos on Youtube

Greg
Updated on February 14, 2022Comments
-
Greg 10 months
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?
-
Felix AballiGuidance: 1) assembly loaded?, 2) assembly loaded matches with origin assembly?, 3) "using" directives pointing to old or none valid references?, 4) .csproj manifest includes source invalid?, 5) a search tool looking regex in the entire solution (every class library and project). 5) check project settings for net framework version build option (collaborate in teams bring on this kind of problen, you must agree net framew. build version in both sides) 6) After that clean and build each by separate and finally, include all references to the destination project/class library. I should work!
-
-
Greg over 12 yearsI'd tried clean and rebuild on your solution but no luck. Tried removing/adding/cleaning/rebuilding just the WPF app project and still no luck too. :(
-
Greg over 12 yearsexcellent - this worked - I had to upgrade my WPF app client to use the full .NET Framework 4. Not sure what impact this will have on the client footprint? I did try downgrading the library I have to the .Net 4 Client Profile however when I did this it had similar issues with the recent Quartz.net 3rd party library I'd just started using. So it seems like using Quartz.net in my library project is ultimately forcing me to have to use the full .Net 4 framework in my UI WPF app.
-
Markero M about 12 yearsI had this same problem as well when I tried referencing a project within the same solution. I upgraded to .NET Framework 4 from the Client Profile framework and I stopped receiving the compile errors.
-
Vitaliy Ulantikov about 11 yearsChecked through my projects - all used 3.5 client profile, but I was still getting errors. Moving to 3.5 full was a helpful workaround, but your doe not explain this. Anyway, thumbs up!
-
Richard over 10 yearsThanks - this helped just now. I recently moved the solution to VS2012 from VS2010, and had created one new class library in VS2012. All of a sudden I was getting this error, and of course it was because the new class library targeted .NET 4.5 while the project referencing it targeted .NET 4.0. Downgrading the new library to target 4.0 fixed it.
-
Jason Coyne about 10 yearsReally would be nice if Visual Studio would give you some sort of hint about this!
-
Triynko about 9 yearsThis is a bizzarre error for sure. When I added the required DLL as a reference, added the using statements, and typed the class names in, they were highlighted in blue as expected and I could right click them and view their definition. Upon compiling, it returned the names to black text and complained that the namespace didn't exist. If I removed and re-added the reference, it would once again highlight everything, and then, once again, when I tried to compile it would complain. I'm surprised the project's target framework caused the DLL to be excluded entirely without warning. Terrible.
-
TruthOf42 about 9 yearsI changed the target of my program using the offending reference from 3.5 to 4.0 and all is dandy now!
-
Kim about 9 yearsThanks for the tip to look at the warnings. My problem was that my test project needed to install the NuGet package for Bcl because my main project was referencing it.
-
Valamas almost 8 yearsA clean followed by a rebuild fixed the issue. However, this issue pops up every day. At least I can get my things done until i sort it out completely.
-
Jon Story about 7 yearsAlthough this answer gives a great description of what needs doing... it has no suggestion on how to do it, which would be a nice addition
-
slugster about 7 years@JonStory Fair enough comment, I assumed that everyone would know how to change the framework that their project is referencing. I'll add some pictures in the next day or so to illustrate that part of it.
-
Jon Story about 7 yearsEven the best of us have sometimes just never had the need to do some tasks. I'm not sure how I've never needed to change the framework and although I have now found it, it hadn't occurred to me before. It's not a deal breaker for the answer, just that I find the very best answers act as a one stop shop for 'describe the problem, state the solution, show how to fix it'
-
Osprey almost 7 yearsI am having this problem but cannot figure out how to "upgrade the framework target". The site works fine when running on my local server but gives me this error when running on the live server. I copied the website folder exactly to the live server. Both instances have the same web.config with <compilation debug="true" targetFramework="4.0" />. I don't "build" a website. I just create the pages in VS2010 and upload the files exactly as they are on my local machine and they usually work. I have other sites on the same live servers and only this one is being problematic.
-
Osprey almost 7 years@slugster . You are right. It turns out that the problem was that I was trying to run the site from a sub-folder in the domain name root and therefore it was not finding the App_Code folder. I moved it to the domain root and it worked.
-
Al Lelopath over 6 yearsHow do I determine if the projects are using the Client Profile or Full .Net? When I look on Project Properties > Application> Target framework, it says
.NET Framework 4
, with no indication of Client Profile or Full. -
Felix Aballi over 6 yearsGuidance: 1) assembly loaded?, 2) assembly loaded matches with origin assembly?, 3) "using" directives pointing to old or none valid references?, 4) .csproj manifest includes source invalid?, 5) a search tool looking regex in the entire solution (every class library and project). 5) check project settings for net framework version build option (collaborate in teams bring on this kind of problen, you must agree net framew. build version in both sides) 6) After that clean and build each by separate and finally, include all references to the destination project/class library. I should work!
-
Yushatak over 6 yearsWhy is it creating new projects at an arbitrary .NET framework of 4 rather than the latest it can create? I could understand having a default, but why that? -_-
-
Chris Davis almost 5 yearsThanks! This prompted me to find the issue I was having. Turns out I had two references to the dependency project, and the one that was taking precedence was a previously built DLL in the bin folder. I deleted the DLL and the rogue reference and did a rebuild, everything compiled correctly then.
-
themefield over 4 yearsHighly recommend this trick whenever finding any referencing issue within a VS solution. It solved my problem in VS2017 after I added in a new project targeting a higher version of .NET framework. I bet there is some caching cleared.
-
mike about 4 yearsSame here: this is what helped (I also didn't have the other version issues). I got error messages for every file that was open, up to 400+ ...although building/running was not a problem. Also: ReSharper's solution-wide-analysis also showed the same errors.
-
Daniel Lerps almost 4 yearsHelped me too this trick. Didn't even have any target version differences. Building was possible, Rider didn't show any problems but VS kept on insisting that all project references were missing...
-
Qwertie over 3 yearsI think you'll find this only works if the Properties panel is opened (right-click a problematic reference and choose Properties.) Now can anyone explain why this works?
-
Prashant Pimpale over 3 years@slugster I have only one projects and getting this error: target framework is 4.0 and VS 2015
-
Cryptc about 3 yearsI had a similar issue with a bad merge in VS 2019. The project compiled successfully, but not the solution. There was actually an error for that project (very strange). It was failing because of an extra file being referenced that had previously been removed, but then re-added from a merge. I removed the file, cleaned up the .csproj file, rebuilt, and all of the references started working again.
-
Matt123 almost 3 yearsWhere can I edit the name of assembly to change it to the right name?
-
user1121956 almost 3 yearsin the project file (.csproj) manually or by right-click on the project -> Properties
-
Kev over 2 yearsThe compiler compiles according to the project build order, so if there is a genuine error in one project it can get lost in a sea of red-herring "type or namespace could not be found" errors - because it just exits when it finds the error, and doesn't get to updating the references. If there aren't too many errors listed, you should be able to find the genuine error. Unfortunately there were 100s of them for me, so this trick really helped me. I guess intelisense doesn't care aout the build order and just compiles projects individually, and that's why you don't get intelisense errors.
-
Coding Enthusiast over 2 yearsSame here with the twist that I had to remove 2 references and re-add them again for it to work. The project getting the error was
Test
and in the 2 references one was also referencing the other (library and UI). -
Hitesh Purohit about 2 yearsI got hint from your answer and updated .net version to latest
-
Andrei Khotko over 1 yearThe advice above helped me in VS2019