C
C#16mo ago
Elmishh

✅ namespaces

every time i try to use namespace and class i get Error CS5001 Program does not contain a static 'Main' method suitable for an entry point what am i supposed to do because
namespace helloword
{
class HelloWorld
{

}
}
namespace helloword
{
class HelloWorld
{

}
}
gives the same error as
namespace helloword
{
class HelloWorld
{
static void Main()
{

}
}
}
namespace helloword
{
class HelloWorld
{
static void Main()
{

}
}
}
22 Replies
Anton
Anton16mo ago
show the project file
Elmishh
Elmishh16mo ago
wdym
Anton
Anton16mo ago
.csproj
Elmishh
Elmishh16mo ago
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

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

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
Anton
Anton16mo ago
huh, it should work does it work if you name the class Program by any chance?
Elmishh
Elmishh16mo ago
no namespaces just dont work for idk why reason
Anton
Anton16mo ago
are there any other files?
Elmishh
Elmishh16mo ago
? its a completely new console app
Anton
Anton16mo ago
are there any other source files in the project
Elmishh
Elmishh16mo ago
no am i supposed to have more files?
Anton
Anton16mo ago
just asking for more context $main
MODiX
MODiX16mo ago
$mains
Anton
Anton16mo ago
$mains
MODiX
MODiX16mo ago
The possible signatures for Main are
public static void Main() { }
public static int Main() { }
public static void Main(string[] args) { }
public static int Main(string[] args) { }
public static async Task Main() { }
public static async Task<int> Main() { }
public static async Task Main(string[] args) { }
public static async Task<int> Main(string[] args) { }
public static void Main() { }
public static int Main() { }
public static void Main(string[] args) { }
public static int Main(string[] args) { }
public static async Task Main() { }
public static async Task<int> Main() { }
public static async Task Main(string[] args) { }
public static async Task<int> Main(string[] args) { }
public is not required (can be any accessibility). Top-level statements are compiled into a Main method and will use an appropriate signature depending on whether args is referenced, the await operator is used and/or an explicit return statement is used. https://docs.microsoft.com/en-US/dotnet/csharp/fundamentals/program-structure/main-command-line
Main() and command-line arguments
Learn about Main() and command-line arguments. The 'Main' method is the entry point of an executable program.
Anton
Anton16mo ago
maybe they want it to be public now?
Elmishh
Elmishh16mo ago
nope tried that too same thing
Anton
Anton16mo ago
well you might be mistaken somewhere, maybe you're running a different project
Elmishh
Elmishh16mo ago
wdym
Anton
Anton16mo ago
maybe someone is trolling you by messing with the msbuild sdk the namespace should not affect this
Elmishh
Elmishh16mo ago
might be the class its the class class isnt working
class Program
{
public static void Main()
{

}
}
class Program
{
public static void Main()
{

}
}
gives the same error im confused now
MR1R0B0T
MR1R0B0T16mo ago
maybe your namespace naming? can you share us snippet of your files in format?
Elmishh
Elmishh16mo ago
it works when using a different thing??? im not sure whats going on created a new project and it somehow worked?