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.
Seen on:
.NET
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
- NullReferenceException System.NullReferenceException: Object reference not set to an instance of an object
- FileNotFoundException assembly Could not load file or assembly 'X, Version=…' or one of its dependencies
- InvalidOperationException InvalidOperationException: Unable to resolve service for type 'X' while attempting to activate 'Y'
Other ways to find it
🧠 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.
Was this page helpful?
Report a correction or suggest an improvement
Last updated 7 Oct 2026