Per the code below, I am getting the following message. I am fairly certain \"why\" I am getting it, I just don\'t know how to rearrange the code to move/remove/replace one of t
The compiler is complaining that it cannot find the type that implements the application entry point (i.e. the Main
method), possibly because you have more than one type in your assembly with a compatible Main
method.
One way to resolve this would be to use the /main
option, as in /main:Form1
. Of course, if the problem is that more than one Main
method exists then the better solution would be to simply remove the ones that you do not intend to use.
I had to do this manually for my implementation of Lox in C#. To "compile with /main
" from the command line, I used
csc /main:Lox.AstPrinter AstPrinter.cs Expr.cs Token.cs TokenType.cs
or, more generally, if you want to compile class Foo
in the Acme
namespace, that also depends on files A.cs, B.cs, and C.cs:
csc /main:Acme.Foo A.cs B.cs C.cs Foo.cs
None of the answers get straight to the point.
The properties Dialog of the project, accessed by right-clicking the project, has an Application tab. On this tab there is a drop down list for 'Startup Object' -- just select the correct class file that Visual Studio should target. As long as there is a Main static void event in that class file, it will target it. Be sure Main is capitalized. This won't work:
static void main(string[] args) { ... code ... }
Here is an image:
In a web project you can right click on an ASPX file and set it as the startup page, very similar thing. Why Visual Studio buries this setting doesn't make sense but this is how you do it.
If you are using Visual Studio to compile/debug your application you should set the entry point of your program in the properties of your project.
First Page -> Application
Startup object -> YourNameSpace.WindowsApplication1.Form1
There is no need to rearrange the code for this. However, looking at the code provided, I can't see any point in which you start the Form1. Inside the Main method is missing the code that starts Form1. Something like
Application.Run(new Form1());