Search code examples
c#.netvisual-studionetwork-programmingwmi

How to solve '...is a 'type', which is not valid in the given context'? (C#)


The following code produces the error:

Error : 'CERas.CERAS' is a 'type', which is not valid in the given context

Why does this error occur?

using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WinApp_WMI2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            CERas.CERAS = new CERas.CERAS();
        }
    }
}

Solution

  • This exception can also be raised when dealing with arrays and forgetting keyword new. (Happened in my case)

    Array Syntax(C#)

    data_type [] arrayName =  new data_type[size];