Error Message "Cs5001 Program Does Not Contain a Static 'Main' Method Suitable for an Entry Point"

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.

  1. 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>

  1. Make the OutputType of the .NET MAUI project exclude the net6.0 target
<!-- xUnit: The condition here only excludes this for the unit test project -->
<OutputType Condition="'$(TargetFramework)' != 'net6.0'">Exe</OutputType>

  1. 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



Leave a reply



Submit