CSC : error CS1555: Could not find 'Main.cs' specified for Main method [/home/runner/Soma/main.csproj]

I’m trying this simple code, but I don’t know why it doesn’t run :woozy_face:

PLEASE HELP! :pray:

using System;

class SomarDoisNumeros {
  public static void Main (string[] args) {
    //Declaração de variáveis
    int num1, num2, soma;
    //Leitura do primeiro número
    Console.WriteLine( "Digite um número:" );
    num1 = int.Parse(Console.ReadLine());
    //Leitura do segundo número
    Console.WriteLine( "Digite outro número:" );
    num2 = int.Parse(Console.ReadLine());
    //Somar
    soma = num1 + num2;
    //Imprimir resultado na tela
    Console.WriteLine( "Soma: " + soma);
  }
}

My code:

https://replit.com/@giulia-donato/Soma-1

Due to the way Replit compiles your code, you have to name your main class as “main”, so changing:

to

class Main {

Should fix your issue.

That caused some error, in the Repl I changed the class to Program and put it in a namespace

using System;

namespace SomarDoisNumeros {
  class Program {
    public static void Main (string[] args) {
      //Declaração de variáveis
      int num1, num2, soma;
      //Leitura do primeiro número
      Console.WriteLine( "Digite um número:" );
      num1 = int.Parse(Console.ReadLine());
      //Leitura do segundo número
      Console.WriteLine( "Digite outro número:" );
      num2 = int.Parse(Console.ReadLine());
      //Somar
      soma = num1 + num2;
      //Imprimir resultado na tela
      Console.WriteLine( "Soma: " + soma);
    }
  }
}

Now it says to update .NET, so that should be in a new (linked) topic, no?

1 Like

You just need to build a fresh template no?

New C# template already comes with .net 6.0 in replit. Since the code is small I think it’s better just to build a new one and paste the code.

2 Likes

Hi, thank you for responding. I made the change you suggested, and it worked :smiling_face_with_three_hearts:
But can you explain to me why it doesn’t work when I put ‘namespace’ above ‘Class’ and write ‘SomarDoisNumeros’? Like, the same error occurs (CS1555)

Hi, thank you for responding. :smiling_face_with_three_hearts:
I tried your code, but unfortunately the same error (CS1555:) is happening to me, and I don’t know why. :sleepy:

So in your original Repl, the .csproj file looks like this:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <StartupObject>SomarDoisNumeros.Program</StartupObject>
  </PropertyGroup>
</Project>

It’s expecting namespace SomarDoisNumeros and class Program.

So my code works, in your original Repl.

Only problem, the .NET version is too low.

So, you created a new Repl.

In a brand new C# Repl, the .csproj file looks like this:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp6.0</TargetFramework>
		<StartupObject>Program</StartupObject>
  </PropertyGroup>

</Project>

So, it is not expecting a namespace.

Also, Firepup’s doesn’t work. It errors (see screenshot below). Use class Program instead.

Got It! Thank you so much! :pray: :smiling_face_with_three_hearts:

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