C
C#2y 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
Anton2y ago
show the project file
Elmishh
ElmishhOP2y ago
wdym
Anton
Anton2y ago
.csproj
Elmishh
ElmishhOP2y 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
Anton2y ago
huh, it should work does it work if you name the class Program by any chance?
Elmishh
ElmishhOP2y ago
no namespaces just dont work for idk why reason
Anton
Anton2y ago
are there any other files?
Elmishh
ElmishhOP2y ago
? its a completely new console app
Anton
Anton2y ago
are there any other source files in the project
Elmishh
ElmishhOP2y ago
no am i supposed to have more files?
Anton
Anton2y ago
just asking for more context $main
MODiX
MODiX2y ago
$mains
Anton
Anton2y ago
$mains
MODiX
MODiX2y 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
Anton2y ago
maybe they want it to be public now?
Elmishh
ElmishhOP2y ago
nope tried that too same thing
Anton
Anton2y ago
well you might be mistaken somewhere, maybe you're running a different project
Elmishh
ElmishhOP2y ago
wdym
Anton
Anton2y ago
maybe someone is trolling you by messing with the msbuild sdk the namespace should not affect this
Elmishh
ElmishhOP2y 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
MR1R0B0T2y ago
maybe your namespace naming? can you share us snippet of your files in format?
Elmishh
ElmishhOP2y ago
it works when using a different thing??? im not sure whats going on created a new project and it somehow worked?
Want results from more Discord servers?
Add your server