All posts

Fix NotFoundError in .NET

Resolve FileNotFoundException and assembly loading errors in .NET applications, covering binding redirects, NuGet restore, and runtime IDs.

.NET NotFoundError and Assembly Loading Issues

The FileNotFoundException: Could not load file or assembly error in .NET indicates a missing DLL, version mismatch, or platform-specific assembly issue.

NuGet Restore

The simplest fix — dependencies weren't restored:

dotnet restore
dotnet build

Version Mismatch

Package A requires version 2.0 of a library, but Package B pulled in version 3.0:

<!-- .csproj — pin the version -->
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />

Platform-Specific Assemblies

Native libraries need the correct runtime identifier:

# Publish for specific platform
dotnet publish -r linux-x64 -c Release
dotnet publish -r win-x64 -c Release
dotnet publish -r osx-arm64 -c Release

Binding Redirects (.NET Framework)

<!-- app.config / web.config -->
<dependentAssembly>
  <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" />
  <bindingRedirect oldVersion="0.0.0.0-13.0.0.0" newVersion="13.0.0.0" />
</dependentAssembly>

Fusion Log for Debugging

Enable fusion logging to see exactly where .NET looks for assemblies:

# .NET Core
set COREHOST_TRACE=1
dotnet run

Self-Contained Deployment

For guaranteed dependency resolution:

dotnet publish -c Release --self-contained true -r linux-x64

Bugsly captures assembly loading failures with the expected version, attempted paths, and calling assembly — critical information for diagnosing deployment issues.

Try Bugsly Free

AI-powered error tracking that explains your bugs. Set up in 2 minutes, free forever for small projects.

Get Started Free