Could not find ‘Program’ specified for Main method

I get this when I run a c# program: CSC : error CS1555: Could not find ‘Program’ specified for Main method [/home/runner/2/sdfsdf.csproj]

The build failed. Fix the build errors and run again.

Hi there @schoolcs! Please could you send the URL of a Repl in which you’re experiencing this problem so we can take a look. :slightly_smiling_face:

Actually, I believe i have managed to find your repl:
The problem is, dotnet is looking for a Program class with a Main function, but you have only provided a class called MainClass. All you need to do to fix your error is rename this class to Program! :+1:

1 Like
Can you please tell me why is it showing error after using “Program” instead of “Main”.

Rename your method from main to Main. Also, you’ll need to change Console.Writeline to Console.WriteLine, and Console.Readline to Console.ReadLine.

Thank you so much , dude.

1 Like

I get the same error message with my experiment repl in c#: main.cs - Testing in C# - Replit.
Any idea what has been causing it?

Take the class out of the namespace (remove lines 7 & 20). Alternatively, remove line 6 from the .csproj file and use top-level statements: have just this in your file:

Console.WriteLine("Press a key to stop the program"); 
Console.ReadKey();  // If any key is pressed it automatically does the action below
Console.WriteLine("stopping program...");

Thanks Umar, that really helps.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.