2

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.stack.imgur.com/5wkYV.png

yehonatan
  • 23
  • 1
  • 4
  • Why are you determined to have 3 `Main`s in your project? Why not just change the names? – Jonesopolis Jul 23 '22 at 22:49
  • Because that's the way I know, also I know that it suppose to have a solution so I wanna know what's wrong with what I did. – yehonatan Jul 23 '22 at 22:53
  • The solution is to have one `Main` in your project. I bet you can use that `/main` arg (or something similar) to specify which project and make this work, but it's confusing and pretty pointless – Jonesopolis Jul 23 '22 at 22:55
  • But I'm going to have a lot of Classes, how am I suppose to do all that with one Main? (sorry I'm new to all this) – yehonatan Jul 23 '22 at 23:02
  • To do what with one Main? @yehonatan – Orion Jul 26 '22 at 12:56

1 Answers1

0

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.

yguerin
  • 196
  • 1
  • 6
  • Sorry for having lack of basic information, but how do I get to the `.csproj`. – yehonatan Jul 24 '22 at 19:15
  • You should find your answer here: https://stackoverflow.com/questions/5129090/how-to-edit-csproj-file ;) In Visual Studio 2022, you also have the possibility to edit your .csproj without unloading the project (right click on your project and look for `Edit [YourProject].csproj`) – yguerin Jul 24 '22 at 23:44