C# Error CS0017 – Program ‘output file name’ has more than one entry point defined

C# Compiler Error Message

Error CS0017 Program ‘output file name’ has more than one entry point defined. Compile with /main to specify the type that contains the entry point.

Reason for the Error

A program can only have one Main method. You will receive this error when there is more than one Main method in your program.

For example, take a look at the below code.

namespace ClassLibrary
{
    public class Class1
    {
        public static void Main()
        {
        }
    }
    public class Class2
    {
        public static void Main()
        {
        }
    }

}

The above .NET Console Application will result in the error when run in your .NET Console Application will result in the C# Compiler Error

Error CS0017 Program has more than one entry point defined. Compile with /main to specify the type that contains the entry point. ConsoleApp1 C:\Users\Senthil\source\repos\ConsoleApp1\ConsoleApp1\Program.cs

Solution

To fix this error, you can remove all Main methods and retain only one of them. An other alternate option is to use the compiler option -main to specify which Main method to use in your .NET program.

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

This C# program calculates and displays an upper triangular matrix based on user input. Problem Statement: The program takes the...
This C# program serves as a demonstration of bitwise operators, which are fundamental operators used for manipulating individual bits in...
This C# program is designed to interchange or swap the columns of a matrix. A matrix is a two-dimensional array...