Troubleshooting “program does not contain a static

2019-01-09 04:47发布

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?

11条回答
够拽才男人
2楼-- · 2019-01-09 05:29

Are the properties on the file set to Compile?

查看更多
地球回转人心会变
3楼-- · 2019-01-09 05:31

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

查看更多
贼婆χ
4楼-- · 2019-01-09 05:36

I was struggle with this error just because one of my class library projects was set acceddentaly to be an console application

so make sure your class library projects is class library in Output type

enter image description here

查看更多
forever°为你锁心
5楼-- · 2019-01-09 05:36

If you have a WPF or Silverlight application, make sure that App.xaml has "ApplicationDefinition" as the BuildAction on the File Properties.

查看更多
闹够了就滚
6楼-- · 2019-01-09 05:43

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

查看更多
你好瞎i
7楼-- · 2019-01-09 05:44

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.

查看更多
登录 后发表回答