2

I have two Projects in one Solution and I want to call a Method from Project1 in Project 2. I already refered the Namespace of Project1 in Project2. The Method from Project1 looks like this:

public void pauseCapturing(bool checkPause) { if (checkPause) { backgroundThread.Suspend(); } else { backgroundThread.Resume(); } } 

In Project2 I call that Method like that:

private void buttonPause_Click(object sender, EventArgs e) { buttonPause.Enabled = false; NamespaceProject1.Class.pauseCapturing(true); } 

When I try to run the code i get the following error:

Error 1 'NamespaceProject1.Class' does not contain a definition for 'pauseCapturing'

I didn't really found a helpful answer to solve my problem.

2
  • @SonerGönül: why he can not have Class? Commented Dec 4, 2013 at 12:43
  • 1
    @SonerGönül: yes class is a KeyWord but not Class. Commented Dec 4, 2013 at 12:46

1 Answer 1

3

you need to create an instance for accessing the methods declared in another class.

in your case you have created method pauseCapturing() as an non-static method hence need an instance to call it.

Note : if the method is declared as a static then you can use class name to access it.

Try This:

NamespaceProject1.Class obj=new NamespaceProject1.Class(); obj.pauseCapturing(true); 
Sign up to request clarification or add additional context in comments.

3 Comments

After changing it I got another error: Error 1 'NamespaceProject1.Class' does not contain a definition for 'pauseCapturing' and no extension method 'pauseCapturing' accepting a first argument of type 'NamespaceProject1.Class' could be found (are you missing a using directive or an assembly reference?)
@user3065722: well , could you please show me your Class design?
I found out that there was something wrong in my settings. I resetted them and then it worked. :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.