Error on Document.Save(Stream) using C# .NET Core on Centos 7 Linux

Hi there.
The following error occurs while trying to save a document to a stream.
This is not happening on while running on Windows machine.
Object reference not set to an instance of an object.
at #=zVi8leGTQnbm9GaGFmQZytcd_7Tja.#=zs9zkBnc=(#=z_Q8hqYh_9lDfBYCdXVn8vmxbDilw #=z5$HqxzNQ_jlU)
at #=z2yTUUg$FjHTSbM2YoB4a5r0=.#=zbWhw7dQ=(#=z_Q8hqYh_9lDfBYCdXVn8vmxbDilw #=z5$HqxzNQ_jlU)
at #=qIHIxCTfGliYKZnMv8TIoblDrjMUw7fvtC7oiNkTHd4M=.#=zpMZTqV7V7gkVi4ameRuxaJ7iY59Q94YHTteifog=(Object #=zGtYIgf4=)
at #=qIHIxCTfGliYKZnMv8TIoblDrjMUw7fvtC7oiNkTHd4M=.#=zJAFWShZ3KUAbfxPMuhvFbqW$UvrpDvEcdhWt9cQnYE1$(MethodBase #=zGtYIgf4=, Boolean #=zomqnFCY=)
at #=qIHIxCTfGliYKZnMv8TIoblDrjMUw7fvtC7oiNkTHd4M=.#=zzoZzK1tZYD7kJWsz9iTJjxU=(#=qIHIxCTfGliYKZnMv8TIoblDrjMUw7fvtC7oiNkTHd4M= #=zGtYIgf4=, #=qBPxOe1hVX9$IFprEYd_T$UkXlb3zBouOgTxTisLuRiU= #=zomqnFCY=)
at #=qIHIxCTfGliYKZnMv8TIoblDrjMUw7fvtC7oiNkTHd4M=.#=z80il4pPQ1MOMVH3lL3pyW17iSWMAFtZePw==()
at #=qIHIxCTfGliYKZnMv8TIoblDrjMUw7fvtC7oiNkTHd4M=.#=zdy4JLLfJL4BU6e0R6EdS1_E44ENg$NTdvP2jVF4=(Boolean #=zGtYIgf4=)
at #=qIHIxCTfGliYKZnMv8TIoblDrjMUw7fvtC7oiNkTHd4M=.#=zpMZTqV7V7gkVi4ameRuxaJ7iY59Q94YHTteifog=(Object #=zGtYIgf4=)
at #=qIHIxCTfGliYKZnMv8TIoblDrjMUw7fvtC7oiNkTH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y1Rg=()
at #=qIHIxCTfGliYKZnMv8TIoblDrjMUw7fvtC7oiNkTHd4M=.#=zfJmRXPzH_z6PGjrZP50rHcKz_2hN0Mvc9A==(Object[] #=zGtYIgf4=, Type[] #=zomqnFCY=, Type[] #=z5F7yewY=, Object[] #=zf4hTPBE=)
at #=qIHIxCTfGliYKZnMv8TIoblDrjMUw7fvtC7oiNkTHd4M=.#=zKvAl7hYk6Y8YMPEBOixKzAyrQYYUtRHF1A==(Stream #=zGtYIgf4=, String #=zomqnFCY=, Object[] #=z5F7yewY=, Type[] #=zf4hTPBE=, Type[] #=zzr6KF88=, Object[] #=zZEOxIWg=)
at #=qIHIxCTfGliYKZnMv8TIoblDrjMUw7fvtC7oiNkTHd4M=.#=z92yA5UIalaA5Qur76pinvqiUwqi1cDMHbw==(Stream #=zGtYIgf4=, String #=zomqnFCY=, Object[] #=z5F7yewY=)
at #=qIHIxCTfGliYKZnMv8TIoblDrjMUw7fvtC7oiNkTHd4M=.#=z7yTmB31iUiMncbf4dNbA4SouifVdBlV6w3GBnd9rGYp_(Stream #=zGtYIgf4=, String #=zomqnFCY=, Object[] #=z5F7yewY=)
at Aspose.Pdf.Document.#=zOg0CDXKzRVfg(Stream #=zPQetvQg=, SaveOptions #=zRJo9$wKQ13vq)
at Aspose.Pdf.Document.Save(Stream output)

Lines of code:
MemoryStream outStream = new MemoryStream();
contractPdf.Save(outStream); //<------ This is where your code is throwing an unhandled exception.

Can you check this?

Thanks

@m.tsiakiris,

Thanks for contacting support.

Can you please share source file to further investigate this issue on our end. Also please share environment details with us so that we may help you out.

Environment details included in subject. =

C# .NET Core on Centos 7 Linux

IT WORKS ON WINDOWS SYSTEM!

Source:

public static byte[] PdfCreator(Application application, string type, string packageName, string packageNotes, string packageOffer, MemoryStream outStream, bool isExternal = false, bool eSignature = false, bool hasSignatureDate = false)
{
ImageStamp tickImage = new ImageStamp(Path.Combine(HostingEnviroment.WebRootPath, PrintingEssentials.PrintingFilepaths.PDFFILES, FileConfiguration.TICK_IMAGE))
{
Height = 10,
Width = 10,
Quality = 20
};

        Aspose.Pdf.Document contractPdf = new Aspose.Pdf.Document(Path.Combine(HostingEnviroment.WebRootPath, PrintingEssentials.PrintingFilepaths.PDFFILES, string.Concat(type, ".pdf")));

        MarginInfo marginInfo = new MarginInfo
        {
            Left = 0,
            Right = 0,
            Top = 0,
            Bottom = 0
        };

        contractPdf.PageInfo.Margin = marginInfo;

        FontRepository.Sources.Add(new FolderFontSource("/usr/share/fonts/open-sans"));

        Aspose.Pdf.Text.Font customFont = FontRepository.FindFont(ApplicationManager.ESIGN_PDF_FONT_NAME);

        TextState customTextStyle = new TextState
        {
            Font = customFont,
            FontSize = 10F,
            FontStyle = FontStyles.Regular,
            LineSpacing = 4,
        };

        foreach (var configItem in LoadConfiguration(string.Concat(type, "AsposeHD.txt"), ConfigurationType.CONTRACT_PRINTING))
        {
            if (configItem.DrawType == 1)
            {
                var objectData = GetPropertyValue(application, configItem.Data);

                if (objectData != null)
                {
                    string data = Convert.ToString(objectData);

                    Logger.LogInformation($"PdfCreator.Create | Property: {configItem.Data} - {data}");

                    if (!string.IsNullOrWhiteSpace(data))
                    {
                        try
                        {
                            customTextStyle.ForegroundColor = string.Equals(configItem.Data, "ContractNumber") ? Aspose.Pdf.Color.Red : Aspose.Pdf.Color.Black;

                            TextFragment sampleText = new TextFragment(data.Length > configItem.MaxLength ? data.Substring(0, configItem.MaxLength) : data);
                            sampleText.TextState.ApplyChangesFrom(customTextStyle);
                            sampleText.IsInLineParagraph = true;
                            sampleText.Position = new Position(configItem.Position.X, configItem.Position.Y);

                            contractPdf.Pages[1].Paragraphs.Add(sampleText);
                        }
                        catch (Exception ex)
                        {
                            Logger.LogError($"Error on aspose create pdf : " +
                                $"data : {data} , " +
                                $"configItem length: {configItem.MaxLength}" +
                                $"configItem data : {configItem.Data}" +
                                $"data length: {data.Length} , X : {configItem.Position.X} , Y : {configItem.Position.Y} " +
                                $"color : - {customTextStyle.ForegroundColor} ," +
                                $"font :  - {customFont}" +
                                $"- error {ex.Message}");
                        }
                    }
                }
            }
            else if (configItem.DrawType == 2)
            {
                if (string.Equals(configItem.Data, "DualPower"))
                {
                    var objectData = GetPropertyValue(application, configItem.Data);

                    Logger.LogInformation($"PdfCreator.Create | Property: {configItem.Data} - {objectData}");

                    if (objectData != null)
                    {
                        TextFragment sampleText = new TextFragment("X");
                        sampleText.TextState.ApplyChangesFrom(customTextStyle);
                        sampleText.IsInLineParagraph = true;
                        sampleText.Position = new Position(configItem.Position.X, configItem.Position.Y);
                        contractPdf.Pages[1].Paragraphs.Add(sampleText);
                    }
                }
                else
                {
                    bool ok = Convert.ToBoolean(GetPropertyValue(application, configItem.Data));

                    Logger.LogInformation($"PdfCreator.Create | Property: {configItem.Data} - {ok}");

                    if (ok)
                    {
                        tickImage.XIndent = (int)configItem.Position.X;
                        tickImage.YIndent = (int)configItem.Position.Y;
                        contractPdf.Pages[1].AddStamp(tickImage);
                    }
                }
            }
        }

        switch (type)
        {
            case "corporateGas":
            case "homeGas":
                string homeGasText = application.GeneralComments;
                string gasPackage = string.Empty;

                if (!string.IsNullOrWhiteSpace(packageOffer))
                    homeGasText += (!string.IsNullOrWhiteSpace(homeGasText)) ? $" - {packageOffer}" : packageOffer;
                if (!string.IsNullOrWhiteSpace(packageNotes))
                    homeGasText += (!string.IsNullOrWhiteSpace(homeGasText)) ? $" - {packageNotes}" : packageNotes;

                PointF homeGasTextCoordinates = new PointF(450F, 423F);
                PointF gasPackageCoordinates = new PointF();

                if (packageName != null && isExternal)
                {
                    gasPackage = "X";
                    switch (packageName.ToUpper())
                    {
                        case "1":
                            gasPackageCoordinates = new PointF(17F, 696F);
                            break;

                        case "2":
                            gasPackageCoordinates = new PointF(142F, 696F);
                            break;

                        case "3":
                            gasPackageCoordinates = new PointF(263F, 696F);
                            break;

                        case "4":
                            gasPackageCoordinates = new PointF(366F, 696F);
                            break;
                    }
                }

                if (!string.IsNullOrWhiteSpace(gasPackage))
                {
                    TextFragment sampleText = new TextFragment(gasPackage);
                    sampleText.TextState.ApplyChangesFrom(customTextStyle);
                    sampleText.IsInLineParagraph = true;
                    sampleText.Position = new Position(gasPackageCoordinates.X, gasPackageCoordinates.Y);

                    contractPdf.Pages[1].Paragraphs.Add(sampleText);
                }

                if (!string.IsNullOrWhiteSpace(homeGasText))
                {
                    TextFragment sampleText = new TextFragment(homeGasText);
                    sampleText.TextState.ApplyChangesFrom(customTextStyle);
                    sampleText.IsInLineParagraph = true;
                    sampleText.Position = new Position(homeGasTextCoordinates.X, homeGasTextCoordinates.Y);

                    contractPdf.Pages[1].Paragraphs.Add(sampleText);
                }
                break;

            default:
                break;
        }

        contractPdf.Save(outStream);

        return outStream.ToArray();
    }

Thank you.

@m.tsiakiris,

Thanks for sharing further details.

We have logged an investigation ticket as PDFNET-48183 in our issue tracking system. We will further look into details of it and keep you posted with the status of its resolution. Please be patient and spare us some time.

We are sorry for the inconvenience.