C
C#6mo 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
333fred6mo 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
Jimmacle6mo 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
Angius6mo ago
Your Program class is partial too, so I assume you're doing something weird
RobertGee
RobertGeeOP6mo ago
in vscode is does it automatically with top level statements?
333fred
333fred6mo ago
No idea what you mean by that
RobertGee
RobertGeeOP6mo 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
Jimmacle6mo 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 User6mo ago
Message Not Public
Sign In & Join Server To View
RobertGee
RobertGeeOP6mo ago
example old project
No description
No description
No description
Jimmacle
Jimmacle6mo 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 User6mo ago
Message Not Public
Sign In & Join Server To View
Jimmacle
Jimmacle6mo ago
regardless, just add a main or a file with top level statements and that will solve the problem
RobertGee
RobertGeeOP6mo ago
i did dotnet new console and yeah true obj / bin should not be added mb
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
RobertGee
RobertGeeOP6mo ago
yep
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
Jimmacle
Jimmacle6mo ago
dotnet new console will make a Program.cs with TLS
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
RobertGee
RobertGeeOP6mo ago
yeah it did
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
Jimmacle
Jimmacle6mo ago
and then you deleted the code from Program.cs
RobertGee
RobertGeeOP6mo ago
oooh
Jimmacle
Jimmacle6mo ago
so it doesn't know what to use as a main anymore
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
RobertGee
RobertGeeOP6mo ago
bro i get it aah yeah okay so if i put anything like writeline we all good
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
Jimmacle
Jimmacle6mo ago
yes, or add an explicit main method $mains
MODiX
MODiX6mo 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 User6mo ago
Message Not Public
Sign In & Join Server To View
RobertGee
RobertGeeOP6mo ago
yeah works thanks, yeah i needed something in their to declare it as TLS
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
RobertGee
RobertGeeOP6mo ago
i do not use #region aha not yet anyways
Jimmacle
Jimmacle6mo ago
this is the second time i've seen regions used so terribly
RobertGee
RobertGeeOP6mo ago
im going through the book series, on the second rn
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
RobertGee
RobertGeeOP6mo ago
i used regions in game dev unity a ton to seperate logic but i guess that game dev
Jimmacle
Jimmacle6mo 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
RobertGeeOP6mo 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 User6mo ago
Message Not Public
Sign In & Join Server To View
RobertGee
RobertGeeOP6mo ago
yeah, i do not treat any content online as "best practices" ngl
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
RobertGee
RobertGeeOP6mo ago
sick thanks guys, me being dumb ngl
Angius
Angius6mo 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