.netwindowsdocker.net-corexbim

.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?


Solution

  • 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.