Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Type or namespace cannot be found, when reference does exist

Tags:

c#

.net

wpf

I have a wpf Application in which I am trying to reference a class library i have created. I have added a reference to the .dll And i have added the using statement to my file, and the intellisense actually sees the new namespace.

Then in my code I am able to create new objects of classes in my added .dll just fine. the intellisense sees all the methods ect..no problem, no errors.

when I try to build my wpf application, all the sudden I get the type or namespace cannot be found error on my added dll.

Then i get errors whenever i am trying to create objects from that .dll.

I don't get what is happening.. why does it work before I build, but when I build it decides it doesn't know where that .dll is i am referencing?

Also i have gone to that class library i am trying to add, and mades sure it builds with no errors.

like image 858
twaldron Avatar asked Jul 08 '11 16:07

twaldron


People also ask

How do you resolve the type or namespace could not be found?

A type or namespace that is used in the program was not found. You might have forgotten to reference (References) the assembly that contains the type, or you might not have added the required using directive. Or, there might be an issue with the assembly you are trying to reference.

Why am I getting error CS0246 the type or namespace name could not be found?

error CS0246: The type or namespace name `________' Could not be found. Are you missing a using directive of assembly reference? This error is caused when the namespace that you are trying to use does not exist.


2 Answers

The most common cause of this is that your .DLL targets the full .NET Framework, but the WPF Application targets the Client Profile.

For example, if your library targets .NET 3.5, make sure your WPF Application targets the full .NET 3.5 or 4.0 framework, not the client profile.

like image 137
Reed Copsey Avatar answered Oct 12 '22 22:10

Reed Copsey


A few thoughts on this matter that you can try:

  • Check that a lower version is not calling a higher version assembly (e.g. .NET 3.5 project is not calling a .NET 4.0 assembly).

  • Clean -> Build (or Rebuild)

  • Manually delete bin/obj folders of both caller and calling projects. This forces everything to be built - the 'hard ' way. This may sound redundant, but has worked for me a couple of times.

  • Restart VS - sometimes, there is just no explanation.

  • Reboot - when nothing else works, give it a break and try again.

like image 26
Joel Avatar answered Oct 12 '22 23:10

Joel