简体   繁体   English

.NET 服务仅在 Docker 上崩溃

[英].NET service crashes ONLY on Docker

I have a .NET 6 service that runs fine on my local Windows 10 machine.我有一个 .NET 6 服务,它在我本地的 Windows 10 机器上运行良好。 When I deploy it on Docker with a multi-stage Dockerfile that uses these images:当我使用使用这些图像的多阶段 Dockerfile 在 Docker 上部署它时:

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). ...它无法加载我的服务加载的本机 DLL(准确地说是 Xbim.Geometry.Engine64)。

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.这个DLL存在于我的运行目录中。

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. Xbim.Geometry.Engine64程序集依赖于 Visual C++ 运行时库中的本机代码。 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.默认情况下,ASP.NET Windows 服务器核心映像不包含这些库,因此 .NET 运行时在尝试加载程序集时失败,如问题所示。

We can add the Visual C++ runtime files to the image by installing the redistributable package :我们可以通过安装可再发行组件 package将 Visual C++ 运行时文件添加到映像中:

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 .对于与此程序集相关的其他一些常见依赖性问题,请参阅此评论

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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