All posts

Fix NotFoundError in .NET When Deploying

Resolve deployment-specific file and assembly not found errors in .NET, covering Docker multi-stage builds and Azure App Service issues.

.NET Deployment NotFoundError

Your .NET app works locally but throws FileNotFoundException after deployment. The root cause is almost always missing files in the publish output.

Docker Multi-Stage Build

The most common mistake — copying from the wrong path:

FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
WORKDIR /src
COPY ["MyApp.csproj", "."]
RUN dotnet restore
COPY . .
RUN dotnet publish -c Release -o /app/publish

FROM mcr.microsoft.com/dotnet/aspnet:8.0
WORKDIR /app
COPY --from=build /app/publish .
ENTRYPOINT ["dotnet", "MyApp.dll"]

Verify the publish output contains everything:

docker build -t myapp .
docker run --rm myapp ls -la /app/

Missing wwwroot

Static files aren't included by default in some project types:

<ItemGroup>
  <Content Include="wwwroot\**" CopyToPublishDirectory="PreserveNewest" />
</ItemGroup>

Azure App Service

Azure expects specific startup commands:

# In Azure App Service Configuration → General settings
# Startup command:
dotnet MyApp.dll

Environment-Specific Config

If appsettings.Production.json is missing:

var builder = WebApplication.CreateBuilder(args);
// This looks for appsettings.{ENVIRONMENT}.json
// Make sure ASPNETCORE_ENVIRONMENT is set
# Kubernetes
env:
  - name: ASPNETCORE_ENVIRONMENT
    value: Production

Bugsly captures startup failures in .NET deployments, alerting your team within seconds when a new deployment breaks — before users are affected.

Try Bugsly Free

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

Get Started Free