Search code examples
c#visual-studio-2010multi-project

Calling function from a class in project 1 from project 2


I have a c# solution. For the solution i have 2 projects setup. One is a web application and one is a class library. I created a class in the class library that has a static method that i want to call from the web application project. I added a reference to project 1 from project 2. I added the using Project1 namespace to a file in project 2 and in the file im trying to call MyClass.MyFunction("test"); but for some reason visual studio is forcing me to put the namespace in front of MyClass for it to work.

example:

Project1.MyClass.MyFunction("test");

does anyone know why its making me use the namespace even though I have it declared in a using statement?


Solution

  • try this using one of these at the top of your web .cs file:

    using MyClass=Project1.MyClass;  // A
    
    using Project1.MyClass;  // B
    

    If option A works, but option B doesn't, then you probably have a MyClass defined in the Project2 namespace.