markneustadt.com

Type or namespace could not be found (are you missing a using directive)?

Recently, a co-worker ran into a problem I had run into many times in the past.  After taking a few minutes to figure things out I was able to help him.  It surprised me that I hadn’t blogged about this before.  So here we go…

Does this look familiar to you?

The type or namespace 'SomeNamespace' could not be found (are you missing a using directive or an assembly reference?)

I bet you’ve probably seen it before.  It happens when you forget to include a reference in your project or if you don’t use a ‘using’ directive to include the assembly.  

But what happens when you do have the assembly referenced and you are using the proper using directive?  This is the problem we ran into recently.

We added our reference to the project.

01

 

 

 

Then, in our code, we can reference the namespace… just like you’d expect.

02

 

 

 

Next, we can begin to code and Visual Studio picks up the IntelliSense and syntax just like you would expect.

03

 

 

 

 

 

 

 

 

 

 

 

 

See how our classes are light blue?  This would indicate that everything is cool, right?  Let’s hit F5 and build this puppy and see what happens.

04

 

 

 

 

 

 

 

 

 

 

 

 

Suddenly, our imported and referenced assembly WHICH WAS JUST DEEMED TO BE OKAY is no good anymore!  What?!  When we look at the errors, we get the following…

05

 

 

 

 

 

 

 

Well that’s stupid.  What happened?  It turns out that the problem is in the Target Framework.  If you right click on the project and choose “Properties” from the popup menu, you’ll see what the target framework is.  In our case, it’s “.NET Framework 4 Client Profile”.

06

 

 

 

 

 

 

 

 

 

 

You must target the same framework as your referenced assemblies.  Drop the target framework list down and see the options.  We need simply “.NET Framework 4″… not the Client Profile version.

07

 

 

 

 

 

 

 

 

 

 

 

Now, we’re able to see that Visual Studio picks up our referenced namespace properly and we can run our application.

08

 

Scroll To Top