Error Message CS5001 Program does not contain a static 'Main' method suitable for an entry point, have multiple classes
May be your program doest not contain Main which is the entry point of console application so replace with and read this
class Hello
{
public void SituationSecondOne()
{
Console.WriteLine(" ");
Console.WriteLine("Choices:");
Console.WriteLine("1: First");
Console.WriteLine("2: Second");
Console.WriteLine(" ");
int ChoiceOne = Convert.ToInt32(Console.ReadLine());
switch (ChoiceOne)
{
case (1):
Console.WriteLine("TEST2");
break;
case (2):
Console.WriteLine("TEST2");
break;
case (1337):
Console.WriteLine(" ");
Console.WriteLine("Thank you for playing");
Console.ReadLine();
Environment.Exit(1);
break;
default:
Console.WriteLine(" ");
Console.WriteLine("Now, let's try that again ... (¬_¬)");
SituationSecondOne();
break;
}
}
static void Main()
{
SecondSet s2 = new SecondSet();
Console.ReadKey();
}
}
Error message CS5001 Program does not contain a static 'Main' method suitable for an entry point
It means that you don't have a suitable entry point for your application at the moment.
That code will nearly work with C# 7.1, but you do need to explicitly enable C# 7.1 in your project file:
<LangVersion>7.1</LangVersion>
or more generally:
<LangVersion>latest</LangVersion>
You also need to rename MainAsync
to Main
. So for example:
Program.cs:
using System.Threading.Tasks;
class Program
{
static async Task Main(string[] args)
{
await Task.Delay(1000);
}
}
ConsoleApp.csproj:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.0</TargetFramework>
<LangVersion>7.1</LangVersion>
</PropertyGroup>
</Project>
... builds and runs fine.
Program does not contain a static 'Main' method suitable for an entry point In .Net MAUI Xunit
You need to make a few modifications to make xUnit work. I have a sample repository here: https://github.com/jfversluis/MauiUnitTestSample
All the modifications are in the csproj
files of both projects and marked with a comment that starts with xUnit
.
- Add
net6.0
as a target in your .NET MAUI project.
<!-- xUnit: Add net6.0; here -->
<TargetFrameworks>net6.0;net6.0-android;net6.0-ios;net6.0-maccatalyst</TargetFrameworks>
- Make the
OutputType
of the .NET MAUI project exclude thenet6.0
target
<!-- xUnit: The condition here only excludes this for the unit test project -->
<OutputType Condition="'$(TargetFramework)' != 'net6.0'">Exe</OutputType>
- In your xUnit project add
UseMaui
if you need to reference .NET MAUI APIs
<!-- xUnit: Add UseMaui if you need access to .NET MAUI APIs-->
<UseMaui>true</UseMaui>
You should now be able to add and run unit tests!
Program does not contain a suitable 'Main' method for entry point
Just create a new Project and if you need the Code of the Program where the Error was copy it and paste it in the new Project
Edit:
If it's an WPF Projects copy the XAML codes
Related Topics
How to Iterate Through a Datatable
Rsa Encryption, Getting Bad Length
Including Pictures in an Outlook Email
How to Create "Embedded" SQL 2008 Database File If It Doesn't Exist
Difference Between Destructor, Dispose and Finalize Method
Find Image Format Using Bitmap Object in C#
Overriding Gethashcode for Mutable Objects
.Net Configuration (App.Config/Web.Config/Settings.Settings)
How to Access Elements of a Jarray (Or Iterate Over Them)
How to Implement a Singleton in C#
Only Primitive Types or Enumeration Types Are Supported in This Context
C# Flickering Listview on Update
Mvc: Where to Put Business Logic
Order of Execution with Multiple Filters in Web API
Compare Compiled .Net Assemblies
How to Reuse Code for Selecting a Custom Dto Object for a Child Property with Ef Core