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 t
A valid entry looks like:
public static class ConsoleProgram
{
[STAThread]
static void Main()
{
Console.WriteLine("Got here");
Console.ReadLine();
}
}
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:
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.
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...?
If you are using a class library project then set Class Library as output type in properties under application section of project.
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:
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
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.
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 2019
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".