[c#] The type or namespace cannot be found (are you missing a using directive or an assembly reference?)

I get the following error when I try to compile my C# program:

The type or namespace name 'Login' could not be found (are you missing a using directive or an assembly reference?)

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace FootballLeague
{
    public partial class MainMenu : Form
    {
    FootballLeagueDatabase footballLeagueDatabase;
    Game game;
    Team team;
    Login login; //Error here

    public MainMenu()
    {
        InitializeComponent();
        changePanel(1);
    }

    public MainMenu(FootballLeagueDatabase footballLeagueDatabaseIn)
    {
        InitializeComponent();
        footballLeagueDatabase = footballLeagueDatabaseIn;
    }

    private void Form_Loaded(object sender, EventArgs e)
    {
    }

    private void gameButton_Click(object sender, EventArgs e)
    {
        int option = 0;
        changePanel(option);
    }
    private void scoreboardButton_Click(object sender, EventArgs e)
    {
        int option = 1;
        changePanel(option);
    }
    private void changePanel(int optionIn)
    {
        gamePanel.Hide();
        scoreboardPanel.Hide();

        string title = "Football League System";

        switch (optionIn)
        {
            case 0:
                gamePanel.Show();
                this.Text = title + " - Game Menu";
                break;
            case 1:
                scoreboardPanel.Show();
                this.Text = title + " - Display Menu";
                break;
        }
    }

    private void logoutButton_Click(object sender, EventArgs e)
    {
        login = new Login();
        login.Show();
        this.Hide();
    }

Login.cs class:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace FootballLeagueSystem
{
    public partial class Login : Form
    {
    MainMenu menu;
    public Login()
    {
        InitializeComponent();
    }

    private void administratorLoginButton_Click(object sender, EventArgs e)
    {
        string username1 = "08247739";
        string password1 = "08247739";

        if ((userNameTxt.Text.Length) == 0)
            MessageBox.Show("Please enter your username!");
        else if ((passwordTxt.Text.Length) == 0)
            MessageBox.Show("Please enter your password!");
        else if (userNameTxt.Text.Equals("") || passwordTxt.Text.Equals(""))
            MessageBox.Show("Invalid Username or Password!");
        else
        {
            if (this.userNameTxt.Text == username1 && this.passwordTxt.Text == password1)
                MessageBox.Show("Welcome Administrator!", "Administrator Login");
            menu = new MainMenu();
            menu.Show();
            this.Hide();
        }
    }

    private void managerLoginButton_Click(object sender, EventArgs e)
    {
        {
            string username2 = "1111";
            string password2 = "1111";

            if ((userNameTxt.Text.Length) == 0)
                MessageBox.Show("Please enter your username!");
            else if ((passwordTxt.Text.Length) == 0)
                MessageBox.Show("Please enter your password!");
            else if (userNameTxt.Text.Equals("") && passwordTxt.Text.Equals(""))
                MessageBox.Show("Invalid Username or Password!");
            else
            {
                if (this.userNameTxt.Text == username2 && this.passwordTxt.Text == password2)
                    MessageBox.Show("Welcome Manager!", "Manager Login");
                menu = new MainMenu();
                menu.Show();
                this.Hide();
            }
        }
    }

    private void cancelButton_Click(object sender, EventArgs e)
    {
        this.Close();
    }

    }
}

Where is the error? What am I doing wrong?

This question is related to c# .net using-directives

The answer is


You need to add the following line:

using FootballLeagueSystem;

into your all your classes (MainMenu.cs, programme.cs, etc.) that use Login.

At the moment the compiler can't find the Login class.


This error comes because compile does not know where to find the class..so it occurs mainly when u copy or import item ..to solve this .. 1.change the namespace in the formname.cs and formname.designer.cs to the name of your project .


If you have Login in a seperate folder within your project make sure that where you are using it you do:

using FootballLeagueSystem.[Whatever folder you are using]


I get this error when my project .net framework version does not match the framework version of the DLL I am linking to. In my case, I was getting:

"The type or namespace name 'UserVoice' could not be found (are you missing a using directive or an assembly reference?).

UserVoice was .Net 4.0, and my project properties were set to ".Net 4.0 Client Profile". Changing to .Net 4.0 on the project cleared the error. I hope this helps someone.


Examples related to c#

How can I convert this one line of ActionScript to C#? Microsoft Advertising SDK doesn't deliverer ads How to use a global array in C#? How to correctly write async method? C# - insert values from file into two arrays Uploading into folder in FTP? Are these methods thread safe? dotnet ef not found in .NET Core 3 HTTP Error 500.30 - ANCM In-Process Start Failure Best way to "push" into C# array

Examples related to .net

You must add a reference to assembly 'netstandard, Version=2.0.0.0 How to use Bootstrap 4 in ASP.NET Core No authenticationScheme was specified, and there was no DefaultChallengeScheme found with default authentification and custom authorization .net Core 2.0 - Package was restored using .NetFramework 4.6.1 instead of target framework .netCore 2.0. The package may not be fully compatible Update .NET web service to use TLS 1.2 EF Core add-migration Build Failed What is the difference between .NET Core and .NET Standard Class Library project types? Visual Studio 2017 - Could not load file or assembly 'System.Runtime, Version=4.1.0.0' or one of its dependencies Nuget connection attempt failed "Unable to load the service index for source" Token based authentication in Web API without any user interface

Examples related to using-directives

The type or namespace name could not be found The type or namespace cannot be found (are you missing a using directive or an assembly reference?) Why is "using namespace std;" considered bad practice?