Search code examples
c#.netreferenceusing

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?


Solution

  • 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();
            }
        }
    }