Skip to content

Exception "System.IO.FileNotFoundException: Could not load file or assembly 'mscorlib, Version=4.0.0.0" when published with "-p:PublishTrimmed=true" #1478

@ismailmmd

Description

@ismailmmd

When a dotnet is published with -p:PublishTrimmed=true parameter the App fails to start with below error,

Unhandled exception. System.IO.FileNotFoundException: Could not load file or assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. The system cannot find the file specified.

File name: 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
   at Microsoft.Extensions.Hosting.GenericHostWebHostBuilderExtensions.ConfigureWebHost(IHostBuilder builder, Action`1 configure)
   at Microsoft.Extensions.Hosting.GenericHostBuilderExtensions.ConfigureWebHostDefaults(IHostBuilder builder, Action`1 configure)
   at API.Program.CreateHostBuilder(String[] args) in /src/API/Program.cs:line 17
   at API.Program.Main(String[] args) in /src/API/Program.cs:line 13
The terminal process "C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.exe -Command docker run --rm -it  -p 5000:5000/tcp api:latest" terminated with exit code: 1.

Steps to reproduce the behavior:

  1. Run the app using publish command and flag -p:PublishTrimmed=false
    dotnet publish "Exchange.Ingestion.API.csproj" -c Release -o /app/publish -p:PublishTrimmed=false
    This will run the app without any issues.
  2. Run the app using publish command and flag -p:PublishTrimmed=true
    dotnet publish "Exchange.Ingestion.API.csproj" -c Release -o /app/publish -p:PublishTrimmed=true
    App will fail to start with error,
Unhandled exception. System.IO.FileNotFoundException: Could not load file or assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. The system cannot find the file specified.
File name: 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
   at Microsoft.Extensions.Hosting.GenericHostWebHostBuilderExtensions.ConfigureWebHost(IHostBuilder builder, Action`1 configure)
   at Microsoft.Extensions.Hosting.GenericHostBuilderExtensions.ConfigureWebHostDefaults(IHostBuilder builder, Action`1 configure)
   at API.Program.CreateHostBuilder(String[] args) in /src/API/Program.cs:line 17
   at API.Program.Main(String[] args) in /src/API/Program.cs:line 13
The terminal process "C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.exe -Command docker run --rm -it  -p 5000:5000/tcp api:latest" terminated with exit code: 1.

Expected behavior
App should start to run and trace logs.

Runtime environment:

  • Instrumentation mode: auto
  • Tracer version: 1.26.3
  • OS: Containarised with mcr.microsoft.com/dotnet/sdk:5.0.102-1-alpine3.12-amd64
  • CLR: .NET CORE 5

Additional context

Metadata

Metadata

Assignees

No one assigned

    Labels

    type:enhancementImprovement to an existing feature

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions