error code CS5001
i have "finished" my code but i have a error "The program does not contain a static 'Main' method suitable for an HLTool entry point"
25 Replies
are there two
main
s?
is there code before the main
?
does another file have code before namespace?just this one have a little code before namespace
your program needs a special method called Main in order for it to actually run
$main
$mains
$mains
The possible signatures for
Main
are 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 the body.
https://docs.microsoft.com/en-US/dotnet/csharp/fundamentals/program-structure/main-command-lineMain() and command-line arguments - C#
Learn about Main() and command-line arguments. The 'Main' method is the entry point of an executable program.
when your program starts this method gets called, then you write the code you want to run inside main
another option is $toplevelcode
Traditionally in C#, the main entry point of any program would be a static
Main
method (see $mains): In C# 9, a feature called top-level statements was added which allows the static Main
method to be omitted in favor of brevity and simplicity, and in C# 10, this was made part of the default console application template:
If you are following a tutorial or example code and your default template looks different, you can still write the exact same code as if you were writing it inside the static Main
method. In addition, you can still write static methods inside top-level code. You can however not use top-level code in more than one file.
If you wish to use the old traditional entry point, you can still use a Program
class with a static Main
method.
https://docs.microsoft.com/en-us/dotnet/csharp/fundamentals/program-structure/top-level-statementsTop-level statements - programs without Main methods - C#
Learn about top-level statements. You can create programs without the ceremony of a Program class and a Main method.
oh ok
so i just have to delete "Menu" and put "Main" ?
you don't have to delete anything
you have to add an entry point
ok
what do you want to happen when you run your program?
its a dll that i put in my game file and when i press a key its a Menu made with imgui that show
should've led with that, that changes things
in that case you probably don't want a main, you want to build your project as a class library instead of an executable
yep
its already with the project output "class library"
not if it's complaining about no main method
type de sortie = output , bibliothèque de classes = class library
have you saved/reloaded VS?
yep
then something is broken
uh wtf
i think i succeeded
to remove the error