0

I am using a the Aspose PDF library that relies on System.Drawing.Common, and running it on .Net Core 2.1. on Linux. I know this will not work in the sandbox, so I'm trying with a custom Docker image (installing libgdiplus, libc6-dev and ttf-mscorefonts-installer as instructed by e.g. Aspose).

I got it working in a dockerized Web API as a Web App, but when used as an Azure Function the calls fail with PlatformNotSupportedException:

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

Related questions #1 and #2 are similar, but they don't use a custom Docker image.

The essence of this question is: do the sandbox limitations on System.Drawing.Common apply also when using a custom Docker image?

For reference, here is the runtime image section from the 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"]

Update: Running the same PDF manipulation code in a .Net Core web app in the Azure Functions docker image works. This indicates that the problem lies within the Azure Functions runtime.

Here's the example snippet to add to the previously mentioned Dockerfile to make it run a Web App instead:

WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT [ "dotnet", "/app/WebApiProjectName.dll" ]
  • This does not look like a problem with Aspose.PDF API, in specific, but some environment related and platform specific problem, in general. You have already installed instructed components too. However, we have logged an investigation ticket with ID **PDFNET-46183** in our issue management system and will let you know our further findings about your scenario. **PS:** I work with Aspose as Developer Evangelist. – Farhan Raza Mar 22 '19 at 22:10
  • Thanks Farhan. I also believe this is related to the Azure Functions runtime, but all help is appreciated very much! – Lauri Helkkula Mar 25 '19 at 15:08
  • Your recent findings make it obvious to be related with Azure Functions runtime. However, we are pleased to inform you that we are working over removing the dependency on System.Drawing namespace so that the API can work smoothly, irrespective of any platform. – Farhan Raza Mar 25 '19 at 20:39
  • If you use Runtime version ~3 for your functions, you should be able to use System.Drawing. I did a quick test yesterday with IronPDF and it seems to be working. – Raihan Iqbal Sep 30 '21 at 00:06

1 Answers1

1

It seems the Azure Functions runtime enforces some limitations regardless of the underlying platform. A valid guess is that the limitations are the same as for Azure Web Apps. Here is a reduced test case for using System.Drawing.Common in a function, which will also fail when run locally on 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");
}