Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Troubleshooting "program does not contain a static 'Main' method" when it clearly does...?

Tags:

c#

compilation

People also ask

How do I fix program does not contain a static main method?

To solve this, go to the project. Right click the project and choose Properties. Then change the Output type to Class Library. Fixed.

How do I fix cs5001 error?

If the Main method has an async modifier, make sure that the selected C# language version is 7.1 or higher and to use Task or Task<int> as the return type. The Main method is only required when compiling an executable file, that is, when the exe or winexe element of the TargetType compiler option is specified.

Why main method is static in C?

A main method is static since it is available to run when the C# program starts. It is the entry point of the program and runs without even creating an instance of the class.


Are the properties on the file set to Compile?


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

enter image description here


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


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


I had this error and solved by this solution.

--> Right click on the project

--> and select "Properties"

--> then set "Output Type" to "Class Library".

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

alt text