Search code examples
c#propertiesprogram-entry-pointvisual-studio-2022

Error CS0017 "Program has more than one entry point defined. Compile with /main to specify the type that contains the entry point." problem


I opened a new project right now, and I opened a new class there with a "Main" inside it. I already read whole over the internet about it and I already got that it happens because I have more than one "Main" method, but I read that when you choose inside the - Properties --> Startup object - your "Main" that you want to open it should be fixed.

The problem is that it doesn't show them at all. What am I suppose to do?

That's the Error:

CS0017 Program has more than one entry point defined. Compile with /main to specify the type that contains the entry point.

My classes:

First -

using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BeginnerProject
{
    internal class Program
    {
        static void Main(string[] args)
        {
            
        }
    }
}

Second -

using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BeginnerProject
{
    internal class FakeCoin
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hi");
        }
    }
}

Third -

using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BeginnerProject
{
    internal class WhyLikeThat
    {
        static void Main(string[] args)
        {
            
        }
    }
}

Properties:

https://i.sstatic.net/5wkYV.png


Solution

  • As described in the official documention, you just need to specify your entry point in your .csproj by using the <StartupObject> or the <MainEntryPoint> tag.

    In your case you should be writting something like <StartupObject>BeginnerProject.FakeCoin</StartupObject> if you want the second class to be your entry point.