Skip to content
Latchkey

C# "CS0006: Metadata file could not be found" in CI

The compiler needed a referenced assembly DLL that does not exist - almost always because a referenced project failed to build first, so its output was never produced. CS0006 is a symptom; the real failure is upstream.

What this error means

Build fails with CS0006 naming a .dll (often under another project’s bin/obj) that "could not be found". A referenced project earlier in the build failed or was skipped, so the consumer cannot find its output.

dotnet build output
CSC : error CS0006: Metadata file
'/src/Shared/bin/Release/net8.0/Shared.dll' could not be found

Common causes

A referenced project failed to build

When Shared fails to compile, its Shared.dll is never produced, and the consuming project then fails CS0006 looking for it. The first error in the log is the true cause.

Build order / parallelism produced a stale reference

A broken incremental state, or building a single project without its dependencies, can leave a referenced output missing.

How to fix it

Fix the first failing project

Scroll to the earliest error in the log - the referenced project’s real failure - and fix that; CS0006 then disappears.

Terminal
dotnet build MyApp.sln -c Release
# read the FIRST error, not the CS0006 that follows it

Build the solution and clean stale state

Build the whole solution so dependencies build first, and clear stale outputs if incremental state is broken.

Terminal
dotnet clean
dotnet build MyApp.sln -c Release

How to prevent it

  • Build the solution (so project references build in order) rather than isolated projects.
  • Treat CS0006 as "look for the earlier failure", not as the root cause.
  • Run a clean build in CI to avoid stale incremental outputs.

Related guides

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