locked
.exe does not contain a static 'Main' method suitable for an entry point

    Question

  • i run a c# file , program.cs, with the scheduler..

    i encountered a error...

    the .exe does not contain a static 'Main' method suitable for an entry point..

    Can anyone tell what is means by the error message?



    Thanks..

    Tuesday, November 04, 2008 5:47 AM

Answers

  • ok...solution already found..
    i run the code well without the line of code.. =) hehe ...thanks for who had help..
    • Marked as answer by wonderfulStar Wednesday, November 05, 2008 8:21 AM
    Wednesday, November 05, 2008 8:21 AM

All replies

  • Every program needs to have a method in it called Main(), that is static. This is what the computer calls when it starts your program. If there isn't one defined, that is the error you'll get.

    For a console application it normally looks like this: static void Main(string[] args) {

    For a forms application, it looks like this: static void Main() {

    DLLs don't normally have one, as they are not intended to run separately.


    How are you running the 'program.cs' file? Normally you run stuff that ends in '.exe' (which you get when you compile your program).

    Ron Whittle
    Tuesday, November 04, 2008 6:30 AM
  • Hi, Ron..

    yup..i already have the static void Main method in my coding..Still in same error..

    i click on the debug to run the code.

    you means the .exe is created every time we run it?


    namespace runSchedule  
    {  
        class Program  
        {  
            static void Main(string[] args)  
            {  
     
    Tuesday, November 04, 2008 6:55 AM
  • No, when you compile the code in Visual Studio, it creates an exe file. If you are in debug mode, this will be in the bin/Debug folder in your project folder. If you are release mode, it's in bin/Release. That's what you want to run.



    Ron Whittle
    Tuesday, November 04, 2008 7:01 AM
  • I running the .cs file..

    i have my coding :
     HttpContext.Current.Response.Flush();  
     


    i got the error NullReferenceException..and it is suggested it use the "New" keyword,.......???


    I don't have idea at all how should i correct it..Can everyone have any suggestion??

    thanks
    Wednesday, November 05, 2008 5:02 AM
  • ok...solution already found..
    i run the code well without the line of code.. =) hehe ...thanks for who had help..
    • Marked as answer by wonderfulStar Wednesday, November 05, 2008 8:21 AM
    Wednesday, November 05, 2008 8:21 AM
  • What I found is that the Program.cs file was not part of the solution.
    I did an add existing item and added the file (Program.cs) back to the solution.

    This corrected the error:
    Error 1 Program '..... does not contain a static 'Main' method suitable for an entry point

    Hope this helps someone in the future.


    AAC, Inc.
    Monday, February 09, 2009 7:40 PM
  • I tried all of these

       //public static void Main()
       //static void Main()
        //static void Main()
            static void Main(string[] args)

       //public static void Main()
       //static void Main()
        //static void Main()
            static void Main(string[] args)

    and got the same error each time

    I've used every Visual Studio since 2005 and I've never seen this before

    Friday, September 21, 2012 4:37 AM