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

14,507

Solution 1

See this to understand Main method signature options.

Solution 2

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)

Solution 3

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

Solution 4

The only valid signatures for Main method are :

static void Main()

and

static void Main(string[])

static void Main(string) is not a valid signature for Main method.

Solution 5

The signature of the main method must be main(String[]), not main(String).

Share:
14,507
Nano HE
Author by

Nano HE

A newbie, China based; And I am new to programming. Work mostly with C#, C++, Perl &amp; Php; Using OS: winxp; C#/C++: Visual Studio 2005/2008; Perl: Active Perl 5.10.1 + Komodo Edit 6; Php: NetBeans IDE 6.7 + XAMPP 1.7.3 Thanks for reading and for the replies! ;) I'm Reading Magic Tree House

Updated on June 24, 2022

Comments

  • Nano HE
    Nano HE almost 2 years

    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);
            }
        }
    }