C
C#7mo ago
! 'Hoplan

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"
No description
25 Replies
Omnissiah
Omnissiah7mo ago
are there two mains? is there code before the main? does another file have code before namespace?
! 'Hoplan
! 'HoplanOP7mo ago
No description
! 'Hoplan
! 'HoplanOP7mo ago
just this one have a little code before namespace
Jimmacle
Jimmacle7mo ago
your program needs a special method called Main in order for it to actually run $main
MODiX
MODiX7mo ago
$mains
Jimmacle
Jimmacle7mo ago
$mains
MODiX
MODiX7mo 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 the body. https://docs.microsoft.com/en-US/dotnet/csharp/fundamentals/program-structure/main-command-line
Main() and command-line arguments - C#
Learn about Main() and command-line arguments. The 'Main' method is the entry point of an executable program.
Jimmacle
Jimmacle7mo ago
when your program starts this method gets called, then you write the code you want to run inside main another option is $toplevelcode
MODiX
MODiX7mo ago
Traditionally in C#, the main entry point of any program would be a static Main method (see $mains):
public static class Program
{
public static void Main()
{
Console.WriteLine("Hello, world!");
}
}
public static class Program
{
public static void Main()
{
Console.WriteLine("Hello, world!");
}
}
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:
Console.WriteLine("Hello, world!");
Console.WriteLine("Hello, world!");
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-statements
Top-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.
! 'Hoplan
! 'HoplanOP7mo ago
oh ok so i just have to delete "Menu" and put "Main" ?
Jimmacle
Jimmacle7mo ago
you don't have to delete anything you have to add an entry point
! 'Hoplan
! 'HoplanOP7mo ago
ok
Jimmacle
Jimmacle7mo ago
what do you want to happen when you run your program?
! 'Hoplan
! 'HoplanOP7mo ago
its a dll that i put in my game file and when i press a key its a Menu made with imgui that show
! 'Hoplan
! 'HoplanOP7mo ago
dunno where i can put it
Jimmacle
Jimmacle7mo ago
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
! 'Hoplan
! 'HoplanOP7mo ago
yep
! 'Hoplan
! 'HoplanOP7mo ago
its already with the project output "class library"
Jimmacle
Jimmacle7mo ago
not if it's complaining about no main method
! 'Hoplan
! 'HoplanOP7mo ago
type de sortie = output , bibliothèque de classes = class library
No description
Jimmacle
Jimmacle7mo ago
have you saved/reloaded VS?
! 'Hoplan
! 'HoplanOP7mo ago
yep
Jimmacle
Jimmacle7mo ago
then something is broken
! 'Hoplan
! 'HoplanOP7mo ago
uh wtf i think i succeeded to remove the error
Want results from more Discord servers?
Add your server