The type or namespace could not be found, but it is there

advertisements

I created a dll which contains a public class with public methods.

I added that dll as a reference in a new project and i'm trying to create a new object from the dll's class

using myDll;

namespace foo
{
    class bar
    {
        static void Main(string[] args)
        {
            myDll.myClass test = new myDll.myClass();
            test.myVoidMethod();
            [...]

but when i try to use test visual studio says that

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

Is that a scope problem?

mydll code (excerpt):

using System;

namespace myDll
{

    public class myClass
    {
       public static void myVoidMethod()
       {
           Console.Write("Hello");
       }
    }
}


Problem : you should not use instance reference variable to accee the static methods.

Solution : You should call static methods using their classname

Try This:

myDll.myClass.myVoidMethod();

EDIT: From Your comments but i want to create a new object

Your error is not coming from first line where you are creating the instance variable , its from second statement while calling static method using instance variable.

You are stillbe able to create an intance for your class

Try This:

myDll.myClass test = new myDll.myClass(); //it works
myDll.myClass.myVoidMethod();