C# "CS0246: The type or namespace could not be found" in CI
The compiler could not resolve a type or namespace name. The using directive is missing, the package that provides the type is not referenced, or a project/transitive reference did not flow to this project.
What this error means
Build fails with CS0246 pointing at a type/namespace and asking "are you missing a using directive or an assembly reference?". It is deterministic source/reference code, not a transient failure.
Services/Cache.cs(7,21): error CS0246: The type or namespace name 'IDistributedCache'
could not be found (are you missing a using directive or an assembly reference?)Common causes
Missing using directive
The namespace that contains the type is not imported in the file, so the unqualified name does not resolve.
Package or project reference missing
The package providing the type was never added, or a ProjectReference/transitive reference that should expose it did not flow to this project.
How to fix it
Add the using and the reference
Import the namespace and ensure the providing package/project is referenced.
using Microsoft.Extensions.Caching.Distributed;Confirm the reference flows to this project
- Add the missing
PackageReferenceorProjectReferenceto the failing project. - For transitive types, reference the providing package directly rather than relying on flow.
- Restore and rebuild so the assembly is available to the compiler.
How to prevent it
- Reference the packages/projects that provide the types you use directly.
- Build locally before pushing to catch unresolved symbols early.
- Use editor "add using" tooling so imports stay in sync with usages.