Compile error

Class library usage, coding and language questions.
omayer
Posts: 458
Joined: Thu Oct 28, 2010 6:14 pm

Compile error

Post by omayer » Thu Sep 20, 2012 5:39 am

Hi, I am trying to call a function before return an error but i got following error -An object reference is required for the non-static field, method, or property 'Psoft.Program.rea()' (CS0120) - C:\SVNviews\Automation\MainSolution\PUpgrade\Program.cs:43,12

namespace Test
{
class Program
{

[STAThread]
public static int Main(string[] args)
{
Keyboard.AbortKey = System.Windows.Forms.Keys.Pause;
int error = 0;

try
{
error = TestSuiteRunner.Run(typeof(Program), Environment.CommandLine);
}
catch (Exception e)
{
Report.Error("Unexpected exception occurred: " + e.ToString());
error = -1;
}

return error;
}


}




}
Tipu

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: error handling

Post by Support Team » Thu Sep 20, 2012 4:08 pm

Hi,

The error state that you must first create an object instance before you can use a non-static field, method, or property. For you information please take a look at the following link: Compiler Error CS0120.
It would also be helpful if you could post the code which throws that error.

Regards,
Markus
Ranorex Support Team
.
Image

omayer
Posts: 458
Joined: Thu Oct 28, 2010 6:14 pm

Re: error handling

Post by omayer » Thu Sep 20, 2012 4:55 pm

Thank you Markus for looking into it
Here is the code that throws an error

Code: Select all

namespace PsoftUpgrade
{
    class Program
    {
  	
        [STAThread]
        public static int Main(string[] args)
        {
            Keyboard.AbortKey = System.Windows.Forms.Keys.Pause;
            int error = 0;

            try
            {
                error = TestSuiteRunner.Run(typeof(Program), Environment.CommandLine);
            }
            catch (Exception e)
            {
                Report.Error("Unexpected exception occurred: " + e.ToString());
                error = -1;
            }
           ReadPlacementResultTable();
            return error;
        }
        
        public void ReadPlacementResultTable()  ///jjust for demo test
        {
        	Console.Write("test");
        	Console.ReadLine();
        }
    	
    }
    
    
    
    
}
Tipu

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Compile error

Post by Support Team » Fri Sep 21, 2012 1:54 pm

Hello,

Try to define your method as static method:
public static void ReadPlacementResultTable()
Regards,
Bernhard
Ranorex Support Team
.
Image

omayer
Posts: 458
Joined: Thu Oct 28, 2010 6:14 pm

Re: Compile error

Post by omayer » Wed Sep 26, 2012 2:42 pm

Thank you Bernhard, will try static
Tipu