My MS Visual C# program was compiling and running just fine. I close MS Visual C# to go off and do other things in life.
I reopen it and (before doing anything else) go to "Publish" my program and get the following error message:
Program C:\myprogram.exe does not contain a static 'Main' method suitable for an entry point
Huh? Yes it does... and it was all working 15 min earlier. Sure, I can believe that I accidentally hit something or done something before I closed it up... but what? How do I troubleshoot this?
My Program.cs file looks like this:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Threading;
namespace SimpleAIMLEditor
{
static class Program
{
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new mainSAEForm());
}
}
}
...and there are some comments in there. There are no other errors.
Help?
Oke, I was looking at this issue as well. And in my case the solutions 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
That's odd. Does your program compile and run successfully and only fail on 'Publish' or does it fail on every compile now?
Also, have you perhaps changed the file's properties'
Build Action
to something other thanCompile
?I had this problem and its because I wasnt using the latest version of C# (C# 7.3 as of writing this) and I had to change the below
internal
access modifier topublic
.or ammend the
.csproj
to use the latest version of C# (this way meant I could still keep the above class asinternal
):My problem is that I accidentally set the arguments for Main
static void Main(object value)
thanks to my refactoring tool. Took couple mins to figure out but should help someone along the way.
It is important that the
Main
method is placed in the class that is properly configured in Visual Studio as a start-up object:SimpleAIMLEditor.Program
from the drop-down for your start-up objectNow run your application again. The error will disappear.