Running unit tests with Aspose throws System.NotSupportedException in Azure pipeline

Hello,
We are using Aspose.PDF in version 22.9.0 in one of our products. This product also requires some unit tests, part of which concerns the actual work performed on a PDF document. For this purpose, we make use of Aspose’s functionality.

While the tests work fine on a Windows system as well as an Ubuntu system (WSL2) with the Microsoft Essential fonts installed, we cannot seem to get it to work when a CI build is run using an Azure pipeline.

The following test fails in the pipeline:

public CiBuildTests()
{
    var lic = Assembly.GetExecutingAssembly().GetManifestResourceStream("Aspose.PdfCiBuild.Tests.Aspose.Total.lic");
    var license = new License();
    license.SetLicense(lic);
}

[Fact]
public void TestComboboxErrors()
{
    // arrange
    var doc = new Document();
    var page = doc.Pages.Add();
    var box = new ComboBoxField(page, new Rectangle(100, 200, 300, 300));
    box.AddOption("hello");
    box.AddOption("world");
    doc.Form.Add(box);
    doc.Save();

    // act
    box.Selected = 1;

    // assert
    box.Value.Should().BeEquivalentTo("hello");
}

It does not fail due to its logic, though. A System.NotSupportedException is thrown with a message about the Symbol fonts, however the rest of the stack trace does not really let me see where exactly this happened.

Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
[xUnit.net 00:00:02.11]     Aspose.PdfCiBuild.Tests.CiBuildTests.TestComboboxErrors [FAIL]
  Failed Aspose.PdfCiBuild.Tests.CiBuildTests.TestComboboxErrors [739 ms]
  Error Message:
   System.NotSupportedException : Format of font "Symbol" is not supported for new composite fonts
  Stack Trace:
     at #=z3tDFAvFbCZ4PoKhyWn1BZYry6Gs6pe4BnL0HzDCtajbR.#=zac5TN51BBe5Mi3yUlg==(#=zpinPMMz9m3Q_Atu6ZWkW7RE= #=z92u2fJQ=)
   at #=znwrRRAS4Loo9fctuiUfYkTU3RWRySOC9nONiNXqv9aHX.#=zJ_B_errdPtbnD6Kp6g==(#=zVTd$FeAbX5TY7Koh6hwiOzo1P0mDZHSmJQ_Ue9A= #=zmjsmumg=, #=zpinPMMz9m3Q_Atu6ZWkW7RE= #=z92u2fJQ=, Boolean #=zItBMMqA=, String& #=z0cJfK14=)
   at #=zfzrBTbmJRnKe2fL4VWGyn1wUE8HsdzNtyrRePbUrtaGxUOAdjDDGFlOoCGiU25BaVdKuF8FGMdmq.#=zilmy1EQ=(String #=z_69pzVc=, #=zVTd$FeAbX5TY7Koh6hwiOzo1P0mDZHSmJQ_Ue9A= #=zmjsmumg=, #=zJRoqtKfEX723e63CZPklJyaOPza6cfKWzqjGkQXhrm0jM6zmDe1Worg= #=zDzpcCaY$JvSa, Boolean #=zjn$q3qM=, Boolean #=zItBMMqA=, #=z8uXS5A0od_U3oJGPlal$1nZ5BXKpYZbNfw==& #=zOnB1gQs=, #=zpMVVDrz8JeI4ieFomzDyRGHJAKGYVTeTmgClqNEtoBIv& #=zNb$Le5ARL0Uf, String& #=zNs3xTeFwTIfk)
   at #=zmvoHFblCpZ9olTXtw_Ou06NL_Jo$CMs65XG9cGVKZ9ZPa66tQPZoRrg=.#=zBLHMfwQ=(#=z8JzRwMDnRYyPoUkGXOTktI5GiVn2YHsuOOxxiO8MqEIi1eHeFTF7ysQsCY$MBpxmQYqNzO0QKGMHBsVjfg==[] #=zq0I04CtrT0f_SBmpFvLZ2C06dlKl, String #=z_69pzVc=, #=zVTd$FeAbX5TY7Koh6hwiOzo1P0mDZHSmJQ_Ue9A= #=zmjsmumg=, #=zJRoqtKfEX723e63CZPklJyaOPza6cfKWzqjGkQXhrm0jM6zmDe1Worg= #=zDzpcCaY$JvSa, Boolean #=zjn$q3qM=, Boolean #=zItBMMqA=, #=z8uXS5A0od_U3oJGPlal$1nZ5BXKpYZbNfw==& #=zsyTstQ0=, #=zpMVVDrz8JeI4ieFomzDyRGHJAKGYVTeTmgClqNEtoBIv& #=zNb$Le5ARL0Uf, String& #=zNs3xTeFwTIfk)
   at Aspose.Pdf.Forms.ComboBoxField.#=zwy2DxGsDrKE3(#=zIVTDYgc5NUhe #=zHMV7zMI=, Annotation #=z4CHmAWY=)
   at Aspose.Pdf.Annotations.WidgetAnnotation.#=zOG51iEs=(Annotation #=z4CHmAWY=)
   at Aspose.Pdf.Forms.Field.#=z1f$5fpE=(#=z6Z1O$wk0ItEOaM82cne6YxGuJl0TZX5Fj4nksIFl5gM3 #=zRfIcKjnFJXHX, Rectangle #=ziz0np0o=)
   at Aspose.Pdf.Annotations.Annotation.Initialize(Page page, Rectangle rect)
   at Aspose.Pdf.Annotations.WidgetAnnotation..ctor(Page #=zVj3TBps=, Rectangle #=ziz0np0o=)
   at Aspose.Pdf.Forms.Field..ctor(Page #=zVj3TBps=, Rectangle #=ziz0np0o=, Boolean #=zxRVHp_YgR6lL)
   at Aspose.Pdf.Forms.ChoiceField..ctor(Page page, Rectangle rect)
   at Aspose.Pdf.Forms.ComboBoxField..ctor(Page page, Rectangle rect)
   at Aspose.PdfCiBuild.Tests.CiBuildTests.TestComboboxErrors() in /home/vsts/work/1/s/test/Aspose.PdfCiBuild.Tests/CiBuildTests.cs:line 28
Results File: /home/vsts/work/_temp/_fv-az43-624_2022-10-06_17_58_40.trx

Failed!  - Failed:     1, Passed:     0, Skipped:     0, Total:     1, Duration: < 1 ms - /home/vsts/work/1/s/test/Aspose.PdfCiBuild.Tests/bin/Debug/net6.0/Aspose.PdfCiBuild.Tests.dll (net6.0)
##[error]Error: The process '/usr/bin/dotnet' failed with exit code 1
Result Attachments will be stored in LogStore

The only (possibly) related issue (207493) I was able to find suggested resolving this by installing the Microsoft Essential fonts. We did that in our pipeline YAML, but it had no effect.
The Azure pipeline looks like the following:

trigger:
- master

variables:
  buildConfiguration: 'Release'

jobs:
- job: demo_build
  displayName: Aspose PDF CI Test Build
  pool:
    vmImage: 'ubuntu-latest'
  steps:
  - task: Bash@3
    displayName: 'Install Microsoft Essential Fonts For Aspose.PDF to work in tests'
    inputs:
      targetType: 'inline'
      script: |
        sudo apt-get update &&
        sudo apt-get install -y libgdiplus
        sudo add-apt-repository multiverse &&
        sudo apt-get update && sudo apt-get install -y ttf-mscorefonts-installer fontconfig &&
        sudo fc-cache -f -v
  - task: DotNetCoreCLI@2
    displayName: Build Projects
    inputs:
      command: 'build'
      projects: '**/*.csproj'
      arguments: '-c $(buildConfiguration)'
  - task: DotNetCoreCLI@2
    displayName: Run Tests
    inputs:
      command: 'test'
      testRunTitle: 'Acro Form Tests'

Do you have any idea on how we could proceed to resolve this issue?
Thanks for your help in advance!

Hi @markus.estermann,

I can not reproduce your environment in short term. Meanwhile, I suggest that you try to understand what fonts are available in your document by following this article. You can also check this article to embed the fonts in the file.

Please let me know if it helps.

Hello @mlyra
Thanks for your inputs. The provided link on embedding fonts concerns Aspose.Words, our problem concerns Aspose.Pdf.

We added the code below to the tests. It did not really help understanding what fonts are causing the issue or missing in the PDF. Note that the PDF is created via the constructor new Document(), there is no backing file or stream.

// this is new
doc.EmbedStandardFonts = true;
foreach (var font in doc.FontUtilities.GetAllFonts())
{
  font.IsEmbedded = true;
  Console.WriteLine($"Contains font: {font.FontName}");
}

// had this before
doc.Save

Hi @mlyra
We were able to resolve the issue via the Azure pipeline itself.
Azure allows defining container jobs, where you can assign a custom Docker image to a certain job.

For the sake of completeness, here is the pipeline:

trigger:
- master

variables:
  buildConfiguration: 'Release'

jobs:
- job: demo_build
  displayName: Aspose PDF CI Test Build
  pool:
    vmImage: 'ubuntu-latest'
  container:
    image: 'azure/aspose.builder:1.0.0'
    endpoint: 'service_connection_name_to_private_registry'
  steps:
  - task: DotNetCoreCLI@2
    displayName: Build Projects
    inputs:
      command: 'build'
      projects: '**/*.csproj'
      arguments: '-c $(buildConfiguration)'
  - task: DotNetCoreCLI@2
    displayName: Run Tests
    inputs:
      command: 'test'
      testRunTitle: 'Acro Form Tests'

The image we used was built from the following Dockerfile:

FROM mcr.microsoft.com/dotnet/sdk:6.0
RUN sed -i'.bak' 's/$/ contrib/' /etc/apt/sources.list
RUN apt-get update; apt-get install -y ttf-mscorefonts-installer fontconfig

@markus.estermann
Thanks for your feedback.