Skip to content
Latchkey

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.

dotnet build output
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.

C#
using Microsoft.Extensions.Caching.Distributed;

Confirm the reference flows to this project

  1. Add the missing PackageReference or ProjectReference to the failing project.
  2. For transitive types, reference the providing package directly rather than relying on flow.
  3. 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.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →