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?
Are the properties on the file set to Compile?
Check your project's properties. On the "Application" tab, select your
Program
class as the Startup object:alt text http://i42.tinypic.com/2vvsxhe.jpg
I was struggle with this error just because one of my
class library
projectswas set acceddentaly
to be an console applicationso make sure your class library projects is class library in Output type
If you have a WPF or Silverlight application, make sure that App.xaml has "ApplicationDefinition" as the BuildAction on the File Properties.
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
For me same error occurred because I renamed the namespace of the Program class.
The "Startup object" field in "Application" tab of the project still referenced the old namespace. Selecting new startup object solved the problem and also removed the obsolete entry from that list.
You may also want to update "Default namespace" field in the same "Application" tab.