Foo Bar
Foo Bar

Reputation: 141

namespace not found!

I created a solution called Foo. Added a class library called Foo.Common Added a console app to call the library code from called ConsoleApp.

I referenced the Foo.Common from ConsoleApp and typed :

using Foo.Common;
public class Program
{
    CommonClass c = new CommonClass();            

    static void Main(string[] args)
    {
    }
}

and get this back :

Error 1 The type or namespace name '**Foo**' could not be found (are you missing a using directive or an assembly reference?) Z:\Foo\Solution1\ConsoleApplication1\Program.cs 3 11 ConsoleApplication1

Why am i getting this?

what s going on?

Upvotes: 7

Views: 14996

Answers (6)

Gerard ONeill
Gerard ONeill

Reputation: 4092

It looks like Foo Bar got this error because his project's target framework was set to the client profile.

Just thought I'd add one more 'solution' -- I created a library that targeted the 4.5 framework. My older project was tarting the 4 framework. I got this error.

Changing the older project to 4.5 made it work.

Upvotes: 0

hspain
hspain

Reputation: 17568

Ensure that under your project settings, the target framework is set as .NET Framework 4 and not .NET Framework 4 Client Profile. I got this same behavior when it was set to Client Profile and it was fixes as soon as I set it to just the regular .NET Framework 4.

Upvotes: 2

mletterle
mletterle

Reputation: 3968

I posted this as a comment, but I want to expand on it here. What's probably happening is it's seeing using as a statement and not a keyword. It appears you have something like the following:

using System;
namespace TestNamespace
{
  using Foo.Common;
  public Class { }
}

Try

using System;
using Foo.Common;
namespace TestNamespace
{
  public Class { } 
}

Instead.

Upvotes: 0

dtb
dtb

Reputation: 217233

Make sure that

  • The ConsoleApp project has a reference to the Foo.Common project (do not browse for Foo.Common.dll),

    Screenshot

  • the file contains a using directive for the namespace in which CommonClass is declared, and

  • CommonClass is declared as public.

So your files should look like this:


CommonClass.cs in Foo.Common project:

namespace Foo.Common
{
    public class CommonClass
    {
        public CommonClass()
        {
        }
    }
}

Program.cs in ConsoleApp project:

using Foo.Common;

namespace ConsoleApp
{
    public class Program
    {
        public static void Main()
        {
            CommonClass x = new CommonClass();
        }
    }
}

Upvotes: 6

user47589
user47589

Reputation:

Did you add a reference to the library? Look under "References" in the console project. If its not there, you need to add it.

Upvotes: 0

Jesus Ramos
Jesus Ramos

Reputation: 23268

Right Click on the new console app solution/project and Add Reference and add the project that contains the Foo namespace

Upvotes: 0

Related Questions