MBU
MBU

Reputation: 5098

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?

Upvotes: 1

Views: 2674

Answers (2)

iandotkelly
iandotkelly

Reputation: 9124

Perhaps you have more than one class called 'MyClass' - one in each project, so its forcing you to choose which one you want.

Upvotes: 0

agent-j
agent-j

Reputation: 27913

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.

Upvotes: 4

Related Questions