1

我有一个在本地 Windows 10 机器上运行良好的 .NET 6 服务。当我使用使用这些图像的多阶段 Dockerfile 将其部署在 Docker 上时:

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

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

...它无法加载我的服务加载的本机 DLL(确切地说是 Xbim.Geometry.Engine64)。

我得到错误:

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'

这个 DLL 存在于我的运行目录中。

我将带有二进制文件的工作正常文件夹从本地计算机复制到容器中,但出现此错误!当我将失败的文件夹从容器复制到本地计算机时,它起作用了!

我究竟做错了什么?我的容器中可能缺少一些东西吗?

4

1 回答 1

1

Xbim.Geometry.Engine64程序集依赖于 Visual C++ 运行时库中的本机代码。默认情况下,ASP.NET Windows Server Core 映像不包含这些库,因此 .NET 运行时在尝试加载程序集时会失败,如问题所示。

我们可以通过安装可再发行包将 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

有关与此程序集相关的其他一些常见依赖问题,请参阅此评论

于 2022-02-22T20:21:35.657 回答