Troubleshooting “program does not contain a static 'Main' method” when it clearly does…?

后端 未结 14 1787
Happy的楠姐
Happy的楠姐 2020-11-30 08:39

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)

相关标签:
14条回答
  • 2020-11-30 08:47

    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.

    0 讨论(0)
  • 2020-11-30 08:48

    What I found is that the Program.cs file was not part of the solution. I did an add existing item and added the file (Program.cs) back to the solution.

    This corrected the error: Error 1 Program '..... does not contain a static 'Main' method suitable for an entry point

    0 讨论(0)
  • 2020-11-30 08:49

    I had this error and solved by this solution.

    --> Right click on the project
    
    --> and select "Properties"
    
    --> then set "Output Type" to "Class Library".
    
    0 讨论(0)
  • 2020-11-30 08:51

    What worked for me: Close MS Visual Studio, then start Visual Studio and open the solution. The error message was then gone.

    0 讨论(0)
  • 2020-11-30 08:52

    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 to public.

    internal class Program
     {
        public static void Main(string[] args)
        {
            //My Code
        }
      }
    

    or ammend the .csproj to use the latest version of C# (this way meant I could still keep the above class as internal):

    <PropertyGroup>
        <LangVersion>latest</LangVersion>
        <NoWin32Manifest>true</NoWin32Manifest>
    </PropertyGroup>
    
    0 讨论(0)
  • 2020-11-30 08:58

    It is important that the Main method is placed in the class that is properly configured in Visual Studio as a start-up object:

    • Right-click your project in project explorer; choose "Properties..."
    • In the properties dialog, choose "Application" tab
    • In the application tab, choose SimpleAIMLEditor.Program from the drop-down for your start-up object

    Now run your application again. The error will disappear.

    0 讨论(0)
提交回复
热议问题