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

后端 未结 14 1788
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 09:05

    In my case (where none of the proposed solutions fit), the problem was I used async/await where the signature for main method looked this way:

    static async void Main(string[] args)
    

    I simply removed async so the main method looked this way:

    static void Main(string[] args)
    

    I also removed all instances of await and used .Result for async calls, so my console application could compile happily.

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

    I was struggle with this error just because one of my class library projects was set acceddentaly to be an console application

    so make sure your class library projects is class library in Output type

    0 讨论(0)
  • 2020-11-30 09:10

    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

    0 讨论(0)
  • 2020-11-30 09:10

    Check your project's properties. On the "Application" tab, select your Program class as the Startup object:

    0 讨论(0)
  • 2020-11-30 09:11

    If you have a WPF or Silverlight application, make sure that App.xaml has "ApplicationDefinition" as the BuildAction on the File Properties.

    0 讨论(0)
  • 2020-11-30 09:11

    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 than Compile?

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