Visual C# Missing partial modifier

I get an error saying "Missing partial modifier on declaration of type 'projectName.Main'; another partial declaration of this type exists. From what i can read about this error, its because i have classes with same name. It does work if i modify the main class to public partial class Main : Form but i want to know why it gives me this error. I need to initializeComponent within Main(), tried creating a method start() and then calling main.Start() in a load event, but then the form loads blank.

namespace projectName
{
    public class Main : Form
    {
        public Main() // Method: Starts the main form
        {
            InitializeComponent();
        }

        public void Main_Load(object sender, EventArgs e)
        // On load of main class, handle events and arguments
        {
            Main main = new Main();
            main.getCurrentDomain();
        }

        public void getCurrentDomain() // Method: Get current domain
        {
            Domain domain = Domain.GetCurrentDomain();
        }
    } // Ends the main class
}
Jon Skeet
people
quotationmark

Assuming this is a Windows Forms app, the problem is that the Visual Studio WinForms designer has created another file (e.g. Main.designer.cs) with:

public partial class Main : Form

to contain designer-generated code.

Your partial class source is effectively merged with that - but it can only happen when both source files declare that the class is partial. Otherwise, you're just trying to declare two classes with the same name in the same namespace, which is prohibited by C#.

people

See more on this question at Stackoverflow