views:

7436

answers:

14

My MS Visual C# program was compiling and running just fine. I close MS Visual C# to go off and do other things in life.

I reopen it and (before doing anything else) go to "Publish" my program and get the following error message:

"Program C:\myprogram.exe does not contain a static 'Main' method suitable for an entry point"

Huh? Yes it does... and it was all working 15 min earlier. Sure, I can believe that I accidentally hit something or done something before I closed it up... but what? How do I troubleshoot this?

My Program.cs file looks like this:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Threading;

namespace SimpleAIMLEditor
{
    static class Program
    {
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            Application.Run(new mainSAEForm());

    }

}

...and there are some comments in there. There are no other errors.

Help?

-Adeena

A: 

Have you accidentally modified your project settings? Do you have source control so you can compare before and after?

Gordon Carpenter-Thompson
+2  A: 

That's odd. Does your program compile and run successfully and only fail on 'Publish' or does it fail on every compile now?

Also, have you perhaps changed the file's properties' Build Action to something other than Compile?

configurator
Yes - it was failing on every compile and yes - I did accidentally change my build action on Program.cs to "none" :)
adeena
A: 

Shouldn't it be public static void main()?

Reddog
No, it doesn't have to be public.
configurator
And it shouldn't be (to prevent other modules calling it accidentally).
Nick
Sometimes it should. Not in this case of a WinForms program, but sometimes small parameterless utility programs exist, and you wish to make it clear that running the executable and calling the public method from code would do the same thing. In that case I think you should expose public void Main().
configurator
+16  A: 

Are the properties on the file set to Compile?

Quibblesome
That was it... I was looking at "build Actions" before I closed it and must have accidentally key-stroked my way to set the Program.cs to not compile. Thanks!
adeena
A: 

Do you have a version control? You can compare the latest versions. Maybe revert to an ealier version of the project file can help.

Ken Yao
A: 
hmemcpy
That only needs to be set when there are two static Main methods.
configurator
A: 

Is your Output Type Windows Application?

Gavin Miller
A: 

Followup:

1) I am embarrassed by my lack of source control. This started out as just a silly little test project for me to get back into coding. It's turning into something "real", so yes - source control is my next priority.
2) I'm embarrassed at how much I still have to learn about the "MS Visual" environment. I miss my command line interface and makefiles!

thanks everyone!

-A

adeena
A: 

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

A: 

I had the same problem and just managed to fix it with the help of the comments above. I got the error on each attempt to compile the application.

My WPF application App.xaml file had Build Action: Page. As soon as I changed that to 'ApplicationDefinition' the project compiled again.

Hope this helps someone else..

-Konstantin

thank you so much Konstantin that worked for me!
msfanboy
A: 

vocês são todos lindos, mas ninguem ajudou .|.

A: 

i also get the same error and build action are compile ....so how to get rid of it???

gaurav
A: 

Hello, Just change from main to Main It works

Raid
A: 

Also make sure that App.xaml has "ApplicationDefinition" as the BuildAction on the File Properties.

MrOnigiri