C
C#5mo ago
RobertGee

✅ Rider Program does not contain Static Main

Program does not contain a static 'Main' method suitable for an entry point Program.Helper.cs
using System.Globalization;

partial class Program
{
private static void ConfigureConsole(string culture = "en-US", bool useComputerCulture = false)
{
OutputEncoding = System.Text.Encoding.UTF8;

if(!useComputerCulture) CultureInfo.CurrentCulture = CultureInfo.GetCultureInfo(culture);

WriteLine($"Current Culture: {CultureInfo.CurrentCulture.DisplayName}");
}

private static void WriteLineInColor(string value, ConsoleColor color = ConsoleColor.White)
{
ConsoleColor previousColor = ForegroundColor;
ForegroundColor = color;
WriteLine(value);
ForegroundColor = previousColor;
}
}
using System.Globalization;

partial class Program
{
private static void ConfigureConsole(string culture = "en-US", bool useComputerCulture = false)
{
OutputEncoding = System.Text.Encoding.UTF8;

if(!useComputerCulture) CultureInfo.CurrentCulture = CultureInfo.GetCultureInfo(culture);

WriteLine($"Current Culture: {CultureInfo.CurrentCulture.DisplayName}");
}

private static void WriteLineInColor(string value, ConsoleColor color = ConsoleColor.White)
{
ConsoleColor previousColor = ForegroundColor;
ForegroundColor = color;
WriteLine(value);
ForegroundColor = previousColor;
}
}
My Program.cs is empty
43 Replies
333fred
333fred5mo ago
Not sure what you're expecting us to say? If you don't have a Main method or a file with top-level statements, then there indeed isn't an entry point
Jimmacle
Jimmacle5mo ago
not a rider problem, i'm not even sure how you got here because no standard C# project template that looks like this
Angius
Angius5mo ago
Your Program class is partial too, so I assume you're doing something weird
RobertGee
RobertGeeOP5mo ago
in vscode is does it automatically with top level statements?
333fred
333fred5mo ago
No idea what you mean by that
RobertGee
RobertGeeOP5mo ago
I get it completely the error etc, just switching from vscode to rider this error is apparent unless i am doing something differently
Jimmacle
Jimmacle5mo ago
this has nothing to do with your editor the way your project looks when you create it depends on the template and options you selected
Unknown User
Unknown User5mo ago
Message Not Public
Sign In & Join Server To View
RobertGee
RobertGeeOP5mo ago
example old project
No description
No description
No description
Jimmacle
Jimmacle5mo ago
i feel like you're not listening to what we're saying you did something to make your project not have a main/TLS no template comes like that
Unknown User
Unknown User5mo ago
Message Not Public
Sign In & Join Server To View
Jimmacle
Jimmacle5mo ago
regardless, just add a main or a file with top level statements and that will solve the problem
RobertGee
RobertGeeOP5mo ago
i did dotnet new console and yeah true obj / bin should not be added mb
Unknown User
Unknown User5mo ago
Message Not Public
Sign In & Join Server To View
RobertGee
RobertGeeOP5mo ago
yep
Unknown User
Unknown User5mo ago
Message Not Public
Sign In & Join Server To View
Jimmacle
Jimmacle5mo ago
dotnet new console will make a Program.cs with TLS
Unknown User
Unknown User5mo ago
Message Not Public
Sign In & Join Server To View
RobertGee
RobertGeeOP5mo ago
yeah it did
Unknown User
Unknown User5mo ago
Message Not Public
Sign In & Join Server To View
Jimmacle
Jimmacle5mo ago
and then you deleted the code from Program.cs
RobertGee
RobertGeeOP5mo ago
oooh
Jimmacle
Jimmacle5mo ago
so it doesn't know what to use as a main anymore
Unknown User
Unknown User5mo ago
Message Not Public
Sign In & Join Server To View
RobertGee
RobertGeeOP5mo ago
bro i get it aah yeah okay so if i put anything like writeline we all good
Unknown User
Unknown User5mo ago
Message Not Public
Sign In & Join Server To View
Jimmacle
Jimmacle5mo ago
yes, or add an explicit main method $mains
MODiX
MODiX5mo 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.
Unknown User
Unknown User5mo ago
Message Not Public
Sign In & Join Server To View
RobertGee
RobertGeeOP5mo ago
yeah works thanks, yeah i needed something in their to declare it as TLS
Unknown User
Unknown User5mo ago
Message Not Public
Sign In & Join Server To View
RobertGee
RobertGeeOP5mo ago
i do not use #region aha not yet anyways
Jimmacle
Jimmacle5mo ago
this is the second time i've seen regions used so terribly
RobertGee
RobertGeeOP5mo ago
im going through the book series, on the second rn
Unknown User
Unknown User5mo ago
Message Not Public
Sign In & Join Server To View
RobertGee
RobertGeeOP5mo ago
i used regions in game dev unity a ton to seperate logic but i guess that game dev
Jimmacle
Jimmacle5mo ago
if this is what the book is teaching you to do, you might want to find a different book regions in general aren't super useful, regions inside a single method is insane
RobertGee
RobertGeeOP5mo ago
its not a "this is the definite coding way" more just to learn some stuff with basic assistance more of a topic coverage
Unknown User
Unknown User5mo ago
Message Not Public
Sign In & Join Server To View
RobertGee
RobertGeeOP5mo ago
yeah, i do not treat any content online as "best practices" ngl
Unknown User
Unknown User5mo ago
Message Not Public
Sign In & Join Server To View
RobertGee
RobertGeeOP5mo ago
sick thanks guys, me being dumb ngl
Angius
Angius5mo ago
The codebase is wild in general lmao Target-type new next to format: passed to Console.WriteLine
Want results from more Discord servers?
Add your server