Alex Gordon
Alex Gordon

Reputation: 60902

Application.Run(new Form1()); giving error

i have the standard code for Program.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;

namespace cellap
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }
    }
}
  1. i created a new project
  2. i imported an existing form1 into it and replaced the existing form1
  3. when i run the app, i get an error on the mentioned line:

    Error 1 The type or namespace name 'Form1' could not be found (are you missing a using directive or an assembly reference?) C:\Users\alexluvsdanielle\AppData\Local\Temporary Projects\cellap\Program.cs 18 33 cellap

does anyone know what the problem is?

Upvotes: 0

Views: 21926

Answers (3)

Raymond Dumalaog
Raymond Dumalaog

Reputation: 353

using ProjectName.folder

Then create an object for the Form1() class like this.

Form1 form1 = new Form1();
Application.Run(form1); 

Also, make sure you actually have a Form1.cs

Upvotes: 1

Jesper Fyhr Knudsen
Jesper Fyhr Knudsen

Reputation: 7937

When you copied the Form did you change it's namespace so the Program.cs can actually see it?

Upvotes: 2

Dennis
Dennis

Reputation: 20571

Check your namespace. The existing Form1 is more than likely in a different namespace than cellap. Check the Form1.designer.cs class too.

Upvotes: 2

Related Questions