The problem is that after I added the new class, the error came up when I did build the solution. What can be wrong?
In Form1, I don’t have any code yet.
I jus
I experienced this issue after adding an xUnit test class to my .NET Core 2.1 project.
The following article gives a detailed explanation of why, and provided the answer that worked for me - here.
Basically, the compiler automatically generates a Main
for the new class. You can provide a directive in your .csproj file to keep this from happening:
<GenerateProgramFile>false</GenerateProgramFile>
Add this to your <PropertyGroup>
section and recompile.
Having two Main methods is just fine. If you receive the error you mentioned then you need only to tell Visual Studio which one you'd like to use.
Here's an example where I have two entry points depending on how I want to dev-test the assembly.
You have two Main methods, and that is why you are getting this error.
From MSDN - Main Method
There can only be one entry point in a C# program. If you have more than one class that has a Main method, you must compile your program with the /main compiler option to specify which Main method to use as the entry point.