dotnet assembly_loading ai_generated true

System.IO.FileNotFoundException: Could not load file or assembly 'AssemblyName, Version=x.x.x.x'. The system cannot find the file specified.

ID: dotnet/filenotfoundexception

Also available as: JSON · Markdown
87%Fix Rate
90%Confidence
70Evidence
2023-01-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
8 active

Root Cause

FileNotFoundException for assemblies occurs when the runtime cannot locate a required DLL. Common causes include missing NuGet dependencies, incorrect publish output, or version mismatches in binding redirects. Fix by restoring packages and verifying the publish output.

generic

Workarounds

  1. 87% success Run dotnet restore and verify all NuGet packages are properly resolved
    Run 'dotnet restore --force' to re-resolve all dependencies. Check the output for warnings about missing or conflicting packages. If using a private NuGet feed, verify the feed URL and credentials in nuget.config
  2. 85% success Publish as self-contained with all dependencies included
    Run 'dotnet publish -c Release --self-contained -r linux-x64' to include all runtime dependencies in the output. This avoids reliance on globally installed assemblies and ensures all required DLLs are in the publish directory

Dead Ends

Common approaches that don't work:

  1. Manually copying DLL files into the output directory 75% fail

    Creates fragile deployments that break on updates; the underlying dependency resolution issue remains and will resurface when packages are updated or the project is rebuilt on another machine

  2. Downgrading the target framework to match an older assembly version 70% fail

    Introduces compatibility issues and loses access to newer APIs; the version mismatch often indicates a transitive dependency conflict that needs proper resolution, not framework downgrade

Error Chain

Leads to:
Preceded by:
Frequently confused with: