-3

Error CS0246 The type or namespace name 'Hardware' could not be found (are you missing a using directive or an assembly reference?) in visual c# When we run this program in Visual Studio 2k19 in C# Console application There is problem showing : Error CS0246 The type or namespace name 'Hardware' could not be found (are you missing a using directive or an assembly reference?)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OOP1
{
    class Program
    {
        static void Main(string[] args)
        {
            Hardware hf = new Hardware();   // error in this line

            Console.ReadLine();
        }
    }
}

--------------

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OOP1.com.inventoryMsystem
{
    class Hardware : Product
    {

        public Hardware()
        {
            Console.WriteLine("Hardware");
        }
    }
}

----------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OOP1.com.inventoryMsystem
{
    class Product
    {

        public Product()
        {
            Console.WriteLine("Product");
        }
    }
}
  • Can you place that line with code? Also it seem like you just dont have dll in reference. – Mertuarez Apr 26 '20 at 12:23
  • 1
    Simply include the `OOP1.com.inventoryMsystem` namespace in your `using` block. You are currently in the namespace `OOP1`, but the class you are trying to use is in `OOP1.com.inventoryMsystem`. – Progman Apr 26 '20 at 15:23

1 Answers1

1

You are instantiating a reference to Hardware, which is a class you have created like so:

class Hardware : Product
    {

        public Hardware()
        {
            Console.WriteLine("Hardware");
        }
    }

However, the Program class, where you are referring to the Hardware class, is in a different namespace than your Hardware class. Program is in the OOP1 namespace, Hardware is in the OOP1.com.InventoryMsystem namespace. Therefore, your Program class does not really know what you are referring to.

To solve, add a Using statement to your Program class, to let this class 'find' your Hardware class thus:

using OOP1.com.InventoryMsystem

Your completed code for the Program class should look very similar to this:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;    

using OOP1.com.InventoryMsystem;

    namespace OOP1
    {
        class Program
        {
            static void Main(string[] args)
            {
                Hardware hf = new Hardware();   // No error now

                Console.ReadLine();
            }
        }
    }
LJH
  • 61
  • 1
  • 6