NullReferenceException when try to save Document into MemoryStream

—ENVIRONMENT—
NET 5.0 launched with a Docker
Aspose.PDF 21.3.0

Faced the following problem.
I load a pdf file into the file stream, perform some manipulations with it.
After that, I want to save the modified PDF file in the MemoryStream for further uploading to Azure Storage.
I get the following error on the Save method:

   private async Task Test(Stream fileStream)
    {
        //Create stream for saving modified PDF:
        await using var pdfStream = new MemoryStream();

        //Generate PDF Document from existing PDF file:
        using var pdf = new Document(fileStream);

        //Smth manipulation with PDF:
        pdf.Info.Title = "Title 123";

        //Trying to save:
        pdf.Save(pdfStream, SaveFormat.Pdf);
    }

----Stack Trace----
{System.NullReferenceException: Object reference not set to an instance of an object.
at #=zV9gaqLDs7tq37p9ji_s_YvaPa99t.#=zzi3k3eY=(#=zom62Wen0KGta9DeaszuV2xAq7eiD #=z73u$UjOuikYN)
at #=zAuqTDSVGFjRJlBSK2ZZDgkU=.#=zw6WtBQQ=(#=zom62Wen0KGta9DeaszuV2xAq7eiD #=z73u$UjOuikYN)
at #=qCnKzzbwMZneKAFTH0eaklA0SiGgrE4IbiFRhh2tvvCo=.#=zfmcQ4lEGLdnUyKTUboI1DWY=(Object #=z8Gm2Bxc=)
at #=qCnKzzbwMZneKAFTH0eaklA0SiGgrE4IbiFRhh2tvvCo=.#=z_Rb1c6lQJ2Y0zNylw16EIXwavKFDXjjuv8SNPDs=(MethodBase #=z8Gm2Bxc=, Boolean #=zL0M6Z1I=)
at #=qCnKzzbwMZneKAFTH0eaklA0SiGgrE4IbiFRhh2tvvCo=.#=zvqSCiUhw9h4I24sD5NmTi1OlMn4qrZWZUUEQD22eCNtI(#=qCnKzzbwMZneKAFTH0eaklA0SiGgrE4IbiFRhh2tvvCo= #=z8Gm2Bxc=, #=qznaZ9H63UU8eUp0qWP3c9LDNbSDEr$KS66l_PWcHCSA= #=zL0M6Z1I=)
at #=qCnKzzbwMZneKAFTH0eaklA0SiGgrE4IbiFRhh2tvvCo=.#=zRo$$wXZ2hIBFJZoHw8EyvrVgwUuV__5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iGgrE4IbiFRhh2tvvCo=.#=z5yRSj4iiUS31ql9h31wcSikDj6rvFUUrxMB9QQA=(Boolean #=z8Gm2Bxc=)
at #=qCnKzzbwMZneKAFTH0eaklA0SiGgrE4IbiFRhh2tvvCo=.#=z5yRSj4iiUS31ql9h31wcSikDj6rvFUUrxMB9QQA=(Boolean #=z8Gm2Bxc=)
at #=qCnKzzbwMZneKAFTH0eaklA0SiGgrE4IbiFRhh2tvvCo=.#=zxpBGI7f1KNUJPwH3kg==()
at #=qCnKzzbwMZneKAFTH0eaklA0SiGgrE4IbiFRhh2tvvCo=.#=zW8nUYFyNUYzrx0Rr0jucg0$YFcmj(Object[] #=z8Gm2Bxc=, Type[] #=zL0M6Z1I=, Type[] #=zvL3P1xg=, Object[] #=ziQODuK4=)
at #=qCnKzzbwMZneKAFTH0eaklA0SiGgrE4IbiFRhh2tvvCo=.#=zgrZ5u5PGPC$$eGkM67nqluI3ZSdpV0yqQg==(Stream #=z8Gm2Bxc=, String #=zL0M6Z1I=, Object[] #=zvL3P1xg=, Type[] #=ziQODuK4=, Type[] #=z4bb1W2U=, Object[] #=z08VKlFM=)
at #=qCnKzzbwMZneKAFTH0eaklA0SiGgrE4IbiFRhh2tvvCo=.#=zkSWZku_9Cy6J8PCLGRyXF1xDzHGqjbesewW4FNQ=(Stream #=z8Gm2Bxc=, String #=zL0M6Z1I=, Object[] #=zvL3P1xg=)
at #=qCnKzzbwMZneKAFTH0eaklA0SiGgrE4IbiFRhh2tvvCo=.#=z8GilYU4UBK1VM0CfaSRZ5im4LbV4ikUvwQ==(Stream #=z8Gm2Bxc=, String #=zL0M6Z1I=, Object[] #=zvL3P1xg=)
at Aspose.Pdf.Document.#=zknqjwvMm3koH(Stream #=zYmCarLg=, SaveOptions #=zKUeVSM0iPemA)
at Aspose.Pdf.Document.#=zhNNMKwgnXtgq(Stream #=zYNJ3CormTKlf, SaveOptions #=z4Gp8a2g=)
at Aspose.Pdf.Document.Save(Stream outputStream, SaveOptions options)
at TestApp.PdfService.CreateAsync(Int32 firstId, Int32 secondId, IFormFile file) in C:\TestApp\PdfService\Services\TestService.cs:line 106}

@goshafb4

The API is being tested at the moment for support of .NET Framework version 5.0. However, could you please make sure that libgdiplus package is installed along with all MS Essential Fonts (package: msttcorefonts)? Please let us know if these packages are installed and issue is still happening. We will further proceed to assist you accordingly.

@asad.ali
Thank you for responding.
I just installed packages libgdiplus & msttcorefonts but exception is still throughs.

FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base
RUN apt-get update && apt-get install -y libgdiplus
...

image.png (18.6 KB)

– Also
I’m trying to call Save method without a docker, and it’s works for me

I figured out the problem. There was a lack of font package.
Please tell me, is this solution still relevant?
Or will we see the ability to install all dependencies through NUGET in new versions of the library?

FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base
RUN sed -i'.bak' 's/$/ contrib/' /etc/apt/sources.list
RUN apt-get update; apt-get install -y ttf-mscorefonts-installer fontconfig
RUN apt-get update && apt-get install -y libgdiplus && apt-get install ttf-mscorefonts-installer
WORKDIR /app
EXPOSE 80

@goshafb4

Yes, it is necessary to install both font and libgdiplus packages to use the API without any issue.

At the moment, you need to install those packages separately by yourself. However, we have logged an investigation ticket as PDFNET-49686 so that we can determine the feasibility to offer a package that includes these dependencies. We will let you know once the ticket is resolved. Please be patient and spare us some time.