none
Language C# error on "Main" statement RRS feed

  • Question

  • I copied the 1st sample of code to compile the sample program & I get an error on the "Main" statement which I don't understand.   Program name is "app".  Error reads:

    Error 1 Program 'C:\Users\johni_000\Documents\Visual Studio 2008\Projects\app\app\obj\Debug\app.exe' does not contain a static 'Main' method suitable for an entry point app

    My statement is:

           public static void Main()

    I don't understand error or how to fix it.

    Can anyone help?

    Tuesday, February 19, 2019 10:43 PM

All replies

  • You didn't show everything, but you're probably missing the attribute. Your static Main should look like this:

    [STAThread]
    static void Main()
    {
         // code
    }


    ~~Bonnie DeWitt [C# MVP]

    http://geek-goddess-bonnie.blogspot.com

    Wednesday, February 20, 2019 2:20 AM
    Moderator
  • Hi johninis,

    Thank you for posting here.

    For your question, what is the type of your project?

    Based on my test, normally, in Console app, your statement would not thrown the exception.

    We could not reproduce the error. Please provide more details.

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, February 20, 2019 2:33 AM
    Moderator
  • Post your code. That line by itself isn't valid. Did you create this using the Console Application project template? If so then the generated code is valid by default.

    Michael Taylor http://www.michaeltaylorp3.net

    Wednesday, February 20, 2019 2:58 PM
    Moderator

  • Error 1 Program 'C:\Users\johni_000\Documents\Visual Studio 2008\Projects\app\app\obj\Debug\app.exe' does not contain a static 'Main' method suitable for an entry point app

    My statement is:

           public static void Main()


    Always state which compiler and version you're using. Features, bugs, 
    language standards implementations and enforcement, etc. vary from one 
    compiler to another and from one version of a given compiler to another.

    It appears that you are using Visual Studio 2008. Is that correct?

    - Wayne

    Wednesday, February 20, 2019 9:29 PM
  • Do you have that inside a class?  Why not show us the whole program?

    Tim Roberts | Driver MVP Emeritus | Providenza & Boekelheide, Inc.

    Thursday, February 21, 2019 8:02 AM
  • Hi

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;

    namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                Console.WriteLine("Main Program Start");
                Console.ReadKey();
            }
        }
    }

    Best Regards.


    Thursday, February 21, 2019 11:05 AM