简体   繁体   中英

.NET service crashes ONLY on Docker

I have a .NET 6 service that runs fine on my local Windows 10 machine. When I deploy it on Docker with a multi-stage Dockerfile that uses these images:

mcr.microsoft.com/dotnet/aspnet:6.0-windowsservercore-ltsc2019 AS base  

mcr.microsoft.com/dotnet/sdk:6.0 AS build  

...it fails to load a native DLL that my service loads (Xbim.Geometry.Engine64 to be exact).

I get the error:

System.IO.FileLoadException: Failed to load Xbim.Geometry.Engine64.dll
 ---> System.IO.FileNotFoundException: Could not load file or assembly 'Xbim.Geometry.Engine.dll, Culture=neutral, PublicKeyToken=null'. The specified module could not be found.
File name: 'Xbim.Geometry.Engine.dll, Culture=neutral, PublicKeyToken=null'

This DLL exists in my running directory.

I copied the working-fine folder with my binaries from my local machine to the container and got this error! When I copied my failing folder from my container to my local machine - it worked!

What am I doing wrong? Could I be missing something in my container?

The Xbim.Geometry.Engine64 assembly depends on native code from the Visual C++ runtime libraries. The ASP.NET Windows Server Core image does not include these libraries by default, so the .NET runtime fails as shown in the question when it tries to load the assemblies.

We can add the Visual C++ runtime files to the image by installing the redistributable package :

RUN powershell -Command Invoke-WebRequest \
    -Uri "https://aka.ms/vs/17/release/vc_redist.x64.exe" \
    -OutFile vc_redist.x64.exe \
 && vc_redist.x64.exe /install /quiet /norestart \
 && del /f vc_redist.x64.exe

For some other common dependency issues related to this assembly, see this comment .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM