I have a .NET 5.0 application (using the
Microsoft.NET.Sdk.Worker SDK) that has
Microsoft.Extensions.Hosting as its only dependency.
Building and running it locally works fine (Windows x64), but running it dockerized does not work.
This is the Dockerfile:
FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build-env WORKDIR /app # Copy csproj and restore as distinct layers COPY *.sln . COPY ProjectName/*.csproj ./ProjectName/ COPY ProjectName.Test/*.csproj ./ProjectName.Test/ RUN dotnet restore # Copy everything else and build COPY . ./ RUN dotnet publish -c Debug -o out # Build runtime image FROM mcr.microsoft.com/dotnet/runtime:5.0 WORKDIR /app COPY --from=build-env /app/out . ENTRYPOINT [ "dotnet", "SolutionName.dll" ]
Running it produces the following error:
container-name_1 | Unhandled exception. System.IO.FileLoadException: Could not load file or assembly 'Microsoft.Extensions.DependencyInjection.Abstractions, Version=188.8.131.52, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The located assembly's manifest definition does not match the assembly reference. (0x80131040) container-name_1 | File name: 'Microsoft.Extensions.DependencyInjection.Abstractions, Version=184.108.40.206, Culture=neutral, PublicKeyToken=adb9793829ddae60' container-name_1 | at ProjectName.Program.CreateHostBuilder(String args) container-name_1 | at ProjectName.Program.Main(String args) in /app/ProjectName/Program.cs:line 18 container-name_container-name_1 exited with code 139
ls -lisa in the
/app directory of the container confirms the dll is there at least:
container-name_1 | 245918 40 -rwxr--r-- 1 root root 37440 Nov 10 2018 Microsoft.Extensions.DependencyInjection.Abstractions.dll
I have tried explicitly including this dependency in my project, but that produces the same error.
I have also tried downgrading the version of
Microsoft.Extensions.Hosting to 3.1.12, but that produces the same error for the same dll but with version 3.1.12.
Can you help me solve this problem?
User contributions licensed under CC BY-SA 3.0