[Solved] Does not contain a static ‘main’ method suitable for an entry point

I began organizing my code to day into seperarate .cs files, and in order to allow the methods that work with the UI to continue to do so I would create the .cs code under the same namespace and public partial class name so the methods could be inter-operable.

My header look like this in four files, including my main core file that calls:

public shell()

Header area of .cs files that work with the UI (and seem to be causing this new conflict):

using System;
using System.Windows.Forms;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.IO;
using System.Data.SqlServerCe;
using System.Diagnostics;
using System.Threading;
using System.Collections.Specialized;
using System.Net;
using System.Runtime.InteropServices;
using watin = WatiN.Core;
using WatiN.Core.Native.InternetExplorer;
using System.Web; 

namespace WindowsFormsApplication1

    public partial class shell : Form

Now when I try to debug/preview my application (BTW this is a Windows Application within Visual Studio 2010 Express) I get this error message:

Does not contain a static ‘main’ method suitable for an entry point

I looked in the application properties in Application->Startup object, but it offers me no options. How can I inform the application to begin at the .cs file that has my InitializeComponent(); command?

  • I’ve looked around so far without a solution.
  • The properties on each .cs file are set to ‘Compile’.
  • I do not see an App.xaml file in my Solutions explorer but I do see a app.config file.

I’m still very new and this is my first attempt at an organizing method with c# code.

Solution #1:

I was looking at this issue as well, and in my case the solution was too easy. I added a new empty project to the solution. The newly added project is automatically set as a console application. But since the project added was a ’empty’ project, no Program.cs existed in that new project. (As expected)

All I needed to do was change the output type of the project properties to Class library

Respondent: atwellpub

Solution #2:

Change the Output Type under the Project > Properties to that of a “Class Library”. By default, this setting may have been set to a “Console Application”.

Respondent: Arne

Solution #3:

Try adding this method to a class and see if you still get the error:

static void Main()
Respondent: Automationtested

Solution #4:

I had this error and solved it using this solution.

  1. Right click on the project
  2. Select “Properties”
  3. Set “Output Type” to “Class Library”.
Respondent: eyossi

Solution #5:

If you don’t have a file named Program.cs, just add a new Class and name it Program.cs.

Then paste this code:

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

 namespace Sales {
     static class Program {

         /// <summary>
         /// The main entry point for the application.
         /// </summary>
         static void Main() {
             Application.Run(new Form1());

Respondent: Ali Ahmadi

Solution #6:

  1. Select App.xaml and display its properties. Set Build Action to ApplicationDefinition.
  2. App.xaml and its corresponding *.cs file must be placed into the root directory of the *.csproj file, i. e. not into a “Source” folder.
Respondent: ROM

Solution #7:

If you do have a Main method but still get this error, make sure that the file containing the Main method has “Build action” set to “Compile” and “Copy to ouput directory” set to “Do not copy”.

Respondent: Roman Volkov

Solution #8:

Edit .csproj file


cheers !

Respondent: simonbs

Solution #9:

Had this problem in VS 2017 caused by:

static async Task Main(string[] args)

(Feature ‘async main’ is not available in C# 7.0. Please use language version 7.1 or greater)



to app.csproj helped.

Solution #10:

For me, the error was actually produced by “Feature ‘async main’ is not available in C# 7.0. Please use language version 7.1 or greater”. This issue was resulting in the “Does not contain a static ‘main’ method suitable for an entry point” message in the Error List, but the Output window showed the “not available” error.
To correct this, I changed the language version from ‘C# latest minor version (default)’ to ‘C# latest minor version (latest)’ under Advanced Build Settings.

Respondent: Tom

Solution #11:

hey i got same error and the solution to this error is just write Capital M instead of small m.. eg:- static void Main()
I hope it helps..

Respondent: Moondog 2112

Solution #12:

Looks like a Windows Forms project that is trying to use a startup form but for some reason the project properties is set to startup being Main.

If you have enabled application framework you may not be able to see that Main is active (this is an invalid configuration).

Respondent: Chetan Soni

Solution #13:

I have both Visual Studio 2017 and Visual Studio 2019

Visual Studio 2019 does not show this error but 2017 does. Try Installing Visual Studio 2019.

Visual Studio 2017

Visual Studio 2017

Visual Studio 2019

Visual Studio 2019

Respondent: Joshua

Solution #14:

When you want to allow paramaters to be specified from the command, they must look like this:

 static void Main(params string[] paramaters)

you cannot specify more than one paramater, otherwise this will also cause the error reported above.

Respondent: Ali Jamal

Solution #15:

For some others coming here:

In my case I had copied a .csproj from a sample project which included <EnableDefaultCompileItems>false</EnableDefaultCompileItems> without including the Program.cs file. Fix was to either remove EnableDefaultCompileItems or include Program.cs in the compile explicitly

Respondent: Gerrie Pretorius

Solution #16:

hellow your main class was deleted so add new class that name set as Main.cs and pest that code or if porblem in window so same problem on that

using System;
using System.Collections.Generic;
using System.Linq;
using Foundation;
using UIKit;

namespace your_PKG_name.iOS
       public class Application
            // This is the main entry point of the application.
            static void Main(string[] args)
                // if you want to use a different Application Delegate class from "AppDelegate"
                // you can specify it here.
                UIApplication.Main(args, null, "AppDelegate");

Respondent: Madison Haynie

Solution #17:

If you are using a class library project then set Class Library as output type in properties under application section of project.

Respondent: yash patel

Solution #18:

After placing the above code in Program.cs, follow these steps:

  1. Right click on the project

  2. Select “Properties”

  3. Set “Output Type” to “Windows Application”

  4. Startup object : namepace.Program

Respondent: Manveer Singh

Solution #19:

If you do indeed have a public static main method it could be your build settings as explained in this question: Troubleshooting “program does not contain a static ‘Main’ method” when it clearly does…?

Respondent: Sidso

Solution #20:

I too have faced this problem. Then I realized that I was choosing Console Application(Package) rather than Console Application.

Respondent: A. Wilson

Solution #21:

I am using Visual Studio and also had this problem. It took me some time, but in my program it was caused because I accidentally deleted a Class named “Program” that is generated automatically.

Solution #22:

For future readers who faced same issue with Windows Forms Application, one solution is to add these lines to your main/start up form class:

    static void Main()
        Application.Run(new MyMainForm());

Then go to project properties > Application > Startup Object dropdown, should see the namespace.MyMainForm, select it, clean and build the solution. And it should work.

Respondent: MaChaToc

Solution #23:

Check to see if the project is set as the “Startup Project”

Right click on the project and choose “Set as Startup Project” from the menu.

Respondent: grumpy

Solution #24:

If you are like me, then you might have started with a Class Library, and then switched this to a Console Application. If so, change this…

namespace ClassLibrary1
    public class Class1

To this…

namespace ConsoleApp1
    class Program
        static void Main(string[] args)
Respondent: James Wierzba

Solution #25:

A valid entry looks like:

public static class ConsoleProgram
        static void Main()
            Console.WriteLine("Got here");

I had issues as I’m writing a web application, but for the dreadly loading time, I wanted to quickly convert the same project to a console application and perform quick method tests without loading the entire solution.

My entry point was placed in /App_Code/Main.cs, and I had to do the following:

  1. Set Project -> Properties -> Application -> Output type = Console Application
  2. Create the /App_Code/Main.cs
  3. Add the code above in it (and reference the methods in my project)
  4. Right click on the Main.cs file -> Properties -> Build Action = Compile

After this, I can set the output (as mentioned in Step 1) to Class Library to start the web site, or Console Application to enter the console mode.

Why I did this instead of 2 separate projects?

Simply because I had references to Entity Framework and other specific references that created problems running 2 separate projects.

For easier solutions, I would still recommend 2 separate projects as the console output is mainly test code and you probably don’t want to risk that going out in production code.

Respondent: Adam Cox

Solution #26:

Perhaps unintentional, but moving my docker file to the solution folder instead of the project eliminated the error. This was helpful when I still wanted to run the solution independently of docker

Respondent: Peter Kindberg

The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .

Most Popular

To Top
India and Pakistan’s steroid-soaked rhetoric over Kashmir will come back to haunt them both clenbuterol australia bossier man pleads guilty for leadership role in anabolic steriod distribution conspiracy