Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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() { InitializeComponent();  } 

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.

like image 264
atwellpub Avatar asked Mar 07 '12 19:03

atwellpub


People also ask

Why main method is static in C?

A main method is static since it is available to run when the C# program starts. It is the entry point of the program and runs without even creating an instance of the class.

What is main method in C#?

The Main method is the entry point of a C# application. (Libraries and services do not require a Main method as an entry point.) When the application is started, the Main method is the first method that is invoked. There can only be one entry point in a C# program.


1 Answers

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

like image 121
Arne Avatar answered Sep 20 '22 15:09

Arne