Compiler error · error CS0246

The type or namespace name 'X' could not be found

Unlike CS0103 (unknown variable), CS0246 is about unknown types — class, struct, interface or namespace names. The compiler is telling you: "I don't know any type by that name."

Cause 1: a typo in your own class name

You declared Studnet… or you use Studnet. Either way, declaration and usage must match exactly:

Student s = new Student();   // no class 'Student' exists… yet
class Student
{
    public string Name;
    public int Id;
}

Student s = new Student { Name = "Ada", Id = 1 };
Console.WriteLine($"Student: {s.Name} (#{s.Id})");

Cause 2: a misspelled .NET type (classic: Sting)

Built-in type keywords like string and int are always known. But their .NET class names — and every other BCL class — must be spelled right. Sting with a missing r is the most famous trigger of this error:

Sting name = "Ada";   // meant 'String'… or better: 'string'
string name = "Ada";          // keyword alias — always available
String same = "Ada";          // .NET class name — also fine, identical type
Console.WriteLine(name == same ? name : "different");

Cause 3: missing using directive (the real-world one)

In Visual Studio this error usually means you're using a class from a namespace you haven't imported. The browser engine pre-imports the essentials (System, System.Collections.Generic), so here it demos the same way — an unknown namespace prefix:

// 'Systm' — misspelled namespace prefix can never resolve:
Systm.Console.WriteLine("hi");

In a real project the fix is one line at the top of the file, or Ctrl+. on the red name:

using System.Text;              // now StringBuilder resolves
using System.Collections.Generic; // now List<T> / Dictionary<K,V> resolve

Frequently asked

What causes error CS0246 in C#?

CS0246 is about unknown TYPES (class, struct, interface, namespace names). CS0103 is about unknown VARIABLES or methods in the current scope. If the error is about the part before a dot, it is CS0246; if about a bare name, usually CS0103.

CS0246 vs CS0103 — what is the difference?

undefined

Cause 4: the package isn't referenced

Some types live in NuGet packages, not the base library. If using Newtonsoft.Json; still gives CS0246, the package isn't installed in this project — a using can only import namespaces that are already referenced. Fix: add the NuGet package (right-click project → Manage NuGet Packages), then the using starts working.

Decision table

Where the name comes fromCheck
Your own classSpelling + case match between class X and every usage; both in the same file or same namespace
.NET base librarySpelling (String vs Sting); try the lowercase keyword (string)
Another namespaceusing directive at the top; Ctrl+. offers to add it
NuGet packagePackage installed + project reference; rebuild after installing

One-minute debug ritual