error CS0246: The type or namespace name 'X' could not be found (are you missing a using directive or an assembly reference?)
The compiler doesn’t know the type — missing using, missing NuGet package/project reference, or a target framework mismatch.
The type or namespace name could not be foundare you missing a using directive or an assembly reference Meaning
After moving code between projects, the reference or package often isn’t added. Packages that don’t support the target framework also produce CS0246 after restore warnings.
Common causes
- Missing using directive
- NuGet package/project reference not added
- Package doesn’t support the target framework
- Typo or wrong casing
⚡ Quick fix
- Add the using or reference (dotnet add package/reference)
- Restore and check warnings (NU1701, NU1202)
- Check the type’s namespace
Detailed fix by platform
Shell
- csharp
dotnet add package Newtonsoft.Json dotnet add reference ../App.Core/App.Core.csproj dotnet restore
How to diagnose
- Namespace — Where is the type?
- References — Package/project referenced?
- Framework — Supported?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
- CS0103 error CS0103: The name 'x' does not exist in the current context
- CS1061 error CS1061: 'X' does not contain a definition for 'Y' and no accessible extension method 'Y' accepting a first argument of type 'X' could be found
- CS8618 warning CS8618: Non-nullable property 'X' must contain a non-null value when exiting constructor. Consider declaring the property as nullable
Most viewed in .NET
- FileNotFoundException assembly Could not load file or assembly 'X, Version=…' or one of its dependencies
- Unable to cast object of type System.InvalidCastException: Unable to cast object of type 'X' to type 'Y'
- NullReferenceException System.NullReferenceException: Object reference not set to an instance of an object
Other ways to find it
Where this error sits
Origin: Application & API. Errors that are often confused with or caused by this one (click to open):
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 13 Oct 2026