我正在使用依赖于 System.Drawing.Common 的 Aspose PDF 库,并在 .Net Core 2.1 上运行它。在 Linux 上。我知道这在沙箱中不起作用,所以我正在尝试使用自定义 Docker 映像(按照例如Aspose的指示安装 libgdiplus、libc6-dev 和 ttf-mscorefonts-installer )。
我让它在 dockerized Web API 中作为 Web 应用程序工作,但是当用作 Azure 函数时,调用失败并出现 PlatformNotSupportedException:
Microsoft.Azure.WebJobs.Host.FunctionInvocationException:执行函数时出现异常:xxx---> System.PlatformNotSupportedException:此平台不支持 System.Drawing。
相关问题#1和#2类似,但它们不使用自定义 Docker 映像。
这个问题的本质是:对 System.Drawing.Common 的沙盒限制是否也适用于使用自定义 Docker 映像时?
作为参考,这里是 Dockerfile 中的运行时映像部分:
FROM mcr.microsoft.com/azure-functions/dotnet:2.0
#libgdiplus, libc6-dev and ttf-mscorefonts are for the aspose library
# sources.list manipulation and eula acceptance stuff is for ttf-mscorefonts
RUN sed -i "s/main/main contrib/g" /etc/apt/sources.list \
&& echo ttf-mscorefonts-installer msttcorefonts/accepted-mscorefonts-eula select true | debconf-set-selections \
&& apt-get update \
&& apt-get install -y --no-install-recommends libgdiplus libc6-dev ttf-mscorefonts-installer
ENV AzureWebJobsScriptRoot=/home/site/wwwroot
COPY --from=installer-env ["/home/site/wwwroot", "/home/site/wwwroot"]
更新:在 Azure Functions 泊坞窗图像中的 .Net Core Web 应用程序中运行相同的 PDF 操作代码有效。这表明问题出在 Azure Functions 运行时中。
这是添加到前面提到的 Dockerfile 以使其运行 Web 应用程序的示例片段:
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT [ "dotnet", "/app/WebApiProjectName.dll" ]