Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Main method entry point with string argument gives "does not contain ... suitable ... entry point" error

Tags:

syntax

c#

Why does the code block below give a compile error of "does not contain a static 'Main' method suitable for an entry point"?

namespace MyConApp
{
    class Program
    {
        static void Main(string args) 
        {
            string tmpString; 
            tmpString = args;
            Console.WriteLine("Hello" + tmpString);
        }
    }
}
like image 276
Nano HE Avatar asked Jan 15 '10 04:01

Nano HE


People also ask

What does “entry point not found” mean?

Thus, if you are unlucky to encounter the error message saying “Entry Point Not Found”, it means that your operating system has no access to this program and then you can’t run it. If you want to fix this error, you can follow the possible fixed given below.

What is an entry point in computer programming?

In computer programming, the first instructions of a program need to be executed through an entry point and the program can access to command line arguments through it. In order to start the execution of a program, the loader or operating system on your computer need to pass control to the entry point of this program.

How to fix entry point not found DLL error in Windows?

When you are running an app, the Entry Point Not Found DLL error appears, you can also try this method. What you need to do is to uninstall the problematic app which triggers the Entry Point Not Found error from your computer and then reinstall it. The following part will show you how to uninstall an app from your computer.

What does 'main has the wrong signature to be entry point'?

But I am getting error stating "Main has the wrong signature to be entry point". Is there a better way to do this? "Main has the wrong signature to be entry point" means that Main need only one params


3 Answers

In the code you provide the problem is that the 'Main' entry point is expecting a array of strings passed from system when the program is invoked (this array can be null, has no elements)

to correct change

static void Main(string args) 

to

static void Main(string[] args) 

You could get the same error if you declared your 'Main' of any type other than 'void' or 'int'

so the signature of the 'Main' method has always to be

static // ie not dynamic, reference to method must exist
public // ie be accessible from the framework invoker
Main   // is the name that the framework invoker will call

string[] <aName> // can be ommited discarding CLI parameters
* is the command line parameters space break(ed)

From MS (...) The Main method can use arguments, in which case, it takes one of the following forms:

static int Main(string[] args)
static void Main(string[] args)
like image 173
ZEE Avatar answered Nov 08 '22 01:11

ZEE


Because the argument is String and not a String Array as expected

like image 43
Sands Avatar answered Nov 08 '22 02:11

Sands


See this to understand Main method signature options.

like image 41
shahkalpesh Avatar answered Nov 08 '22 01:11

shahkalpesh