Does not contain a static "core" method suitable for an entry point

Today I started organizing my code in separate .cs files, and so that the methods that work with the user interface continue to do this, I would create .cs code under the same namespace and open partial class name so that the methods can be compatible.

My header looks like this in four files, including the main file, which calls:

public shell() { InitializeComponent(); } 

The header area of ​​the .cs files that work with the user interface (and seem to cause 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 / view my application (by the way, this is a Windows application in Visual Studio 2010 Express), I get the following error message:

Does not contain static main method suitable for entry point

I looked in the application properties in Application-> Startup object, but it does not offer me any options. How can I tell the application to start with a .cs file that has my InitializeComponent (); team?

  • I have looked around so far without a solution.
  • The properties of each .cs file are set to Compile.
  • I do not see the App.xaml file in my solution explorer, but I see the app.config file.

I'm still very new, and this is my first attempt to organize a method using C # code.

+62
c # visual-studio-2010
Mar 07 '12 at 19:20
source share
23 answers

I also considered this problem, and in my case the solution was too simple. I added a new empty project to the solution. A newly added project is automatically installed as a console application. But since the added project was an β€œempty” project, there was no Program.cs in this new project. (As expected)

All I had to do was change the output type of the project properties to the class library

+103
Jun 06 '12 at 19:01
source share

Change the output type in Project> Properties to the "Class Library" properties. By default, this option can be set to "Console Application".

+62
Aug 06 '14 at 9:01
source share

Try adding this method to the class and see if you all get an error:

 [STAThread] static void Main() { } 
+15
Jun 06 2018-12-06T00:
source share

If you do not 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> [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1()); } } } 
+11
May 14 '13 at 19:16
source share

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

+6
Nov 05 '14 at 11:41
source share

Hey, I got the same error, and the solution to this error is to simply write Capital M instead of a small m .. for example: - static void Main () I hope this helps ...

+4
Dec 30
source share

I had this error and solved this solution.

 --> Right click on the project --> and select "Properties" --> then set "Output Type" to "Class Library". 
+4
Jun 22 '19 at 11:44 on
source share
  • Select App.xaml and show its properties. Set Build Action to ApplicationDefinition .
  • App.xaml and the corresponding * .cs file should be placed in the root directory of the * .csproj file, i.e. e. and not in the Source folder.
+3
Jun 21 '16 at 16:37
source share

It looks like a Windows Forms project that is trying to use a startup form, but for some reason the project properties are set to "Home."

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

+2
Mar 07 '12 at 19:32
source share

If you want to allow parameters to specify a command, they should look like this:

  [STAThread] static void Main(params string[] paramaters) { 

you cannot specify more than one parameter, otherwise it will also lead to the error described above.

+1
Jun 20 '17 at 11:06
source share

For some others coming here:

In my case, I copied .csproj from a sample project that included <EnableDefaultCompileItems>false</EnableDefaultCompileItems> without including the Program.cs file. It was fixed either to remove EnableDefaultCompileItems, or to explicitly include Program.cs in compilation

+1
Mar 08 '18 at 14:35
source share

hellow your main class has been removed, so add a new class with the name set to Main.cs and add this code to the code, or if the problem is in the window, the same problem

 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"); } } } 
+1
Apr 21 '18 at 5:09
source share

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

+1
Feb 28 '19 at 10:27
source share

If you really have a public static main method, it could be your build settings, as explained in this question: The troubleshooter "does not contain the static method 'Main'" when it is clear ...?

0
Mar 07 '12 at 19:26
source share

I also ran into this problem. Then I realized that I was choosing a console application (package) rather than a console application.

0
Mar 29 '16 at 11:05
source share

I am using Visual Studio as well as this problem. It took me a while, but in my program this was due to the fact that I accidentally deleted a class called "Program", which is automatically generated.

0
Sep 20 '16 at 8:11
source share

For future readers who encounter the same problem with the Windows Forms Application, one solution is to add these lines to your main / initial form class:

  [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new MyMainForm()); } 

Then go to project properties> Application> Launch drop-down list, you will see the namespace. MyMainForm, select it, clean and build the solution. And it should work.

0
Oct 06 '16 at 20:43
source share

Check if the project is set as "Startup Project"

Right-click on the project and select "Install as Startup Project" from the menu.

0
Feb 24 '17 at 22:55
source share

If you are like me, then perhaps you started with a class library and then switched to a console application. If so, change this ...

 namespace ClassLibrary1 { public class Class1 { } } 

To that...

 namespace ConsoleApp1 { class Program { static void Main(string[] args) { } } } 
0
Mar 15 '18 at 15:57
source share

The actual entry looks like this:

 public static class ConsoleProgram { [STAThread] static void Main() { Console.WriteLine("Got here"); Console.ReadLine(); } } 

I had problems writing a web application, but during the terrible loading time I wanted to quickly convert the same project to a console application and perform quick method tests without loading the whole 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 /App_Code/Main.cs
  3. Add the above code (and method references in my project)
  4. Right-click Main.cs β†’ Properties β†’ Create Action = Compile.

After that, I can set the output (as indicated in step 1) for the class library to launch the website, or for the console application to enter console mode.

Why did I do this instead of 2 separate projects?

Just because I had links to the Entity Framework and other specific links that created problems when starting 2 separate projects.

For simpler solutions, I still recommend 2 separate projects, because the console output is basically test code, and you probably won't want to risk it in the production code.

0
Sep 18 '18 at 12:00
source share

Salaam, 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

0
Jul 01 '19 at 5:26
source share

For me, the error was actually caused by the fact that the "async main" function is not available in C # 7.0. Please use the language version 7.1 or higher. " This problem led to the message "Does not contain a static main method suitable for the entry point" in the error list, but the error message "inaccessible" was displayed in the "Output" window. To fix this, I changed the language version from 'C # last minor version (default)' to 'C # last minor version (last)' in the Advanced Build Settings section.

0
Sep 23 '19 at 13:45
source share

A simple solution.

1.BUILD β†’ CLEAN PROJECT NAME (it will clear your previous incomplete collection "it looks like an update")

2.BUILD β†’ BUILD PROJECT-NAME.

then you can just run your Script, it will work. Please find the Application!

-four
Jun 09 '13 at 6:45
source share



All Articles