System.Drawing.Common 可以在带有自定义 docker 图像的 Azure Functions 中使用吗?

Can System.Drawing.Common be used in Azure Functions with a custom docker image?

我正在使用依赖于 System.Drawing.Common 的 Aspose PDF 库,并且 运行 在 .Net Core 2.1 上使用它。在 Linux 上。我知道这在 sandbox, so I'm trying with a custom Docker image (installing libgdiplus, libc6-dev and ttf-mscorefonts-installer as instructed by e.g. Aspose).

中不起作用

我让它在 docker 化 Web API 中作为 Web 应用程序工作,但是当用作 Azure 函数时,调用失败并出现 PlatformNotSupportedException:

Microsoft.Azure.WebJobs.Host.FunctionInvocationException: Exception while executing function: xxx---> System.PlatformNotSupportedException: System.Drawing is not supported on this platform.

相关问题#1 and 类似,但他们没有使用自定义Docker图像。

这个问题的实质是:System.Drawing.Common 的沙盒限制在使用自定义 Docker 图像时是否也适用?

作为参考,这里是 Docker 文件中的 运行 时间图像部分:

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 docker 图像中的 .Net Core Web 应用程序中的相同 PDF 操作代码有效。这表示问题出在 Azure Functions 运行time.

这是要添加到前面提到的 Docker 文件以使其 运行 成为 Web 应用程序的示例片段:

WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT [ "dotnet", "/app/WebApiProjectName.dll" ]

似乎 Azure Functions 运行time 强制实施了一些限制,与底层平台无关。一个有效的猜测是限制与 Azure Web Apps 相同。这是一个在函数中使用 System.Drawing.Common 的简化测试用例,当 运行 在 Windows 上本地时也会失败:

[FunctionName("MatrixTester")]
public static async Task<IActionResult> Run(
    [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = null)] HttpRequest req)
{
  try
  {
    new Matrix(1, 2, 3, 4, 5, 6);
  }
  catch (PlatformNotSupportedException pnse)
  {
    return new OkObjectResult("Matrix not supported. Details: " + pnse);
  }
  return new OkObjectResult("Matrix is supported on this platform");
}