Exception "Null Reference" on .Net Core 3.1 when saving PDF using Aspose.PDF for .NET

Open a PDF (new Document) then Save the PDF (doc.Save) without doing anything else and the Save will fail with a nullreference exception. I am running a current version of dotnet core.
$ dotnet --version
3.1.101

To check it wasn’t something I was doing I took a simple c# code example from Aspose such as Aspose.Pdf.Examples.CSharp.AsposePDF.DocumentConversion.PDFToPDFA

See the strange looking stack trace below…

$ dotnet run
Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object.
at #=zfKhF9SKUJ0KwXhVk175rCUZm4kJB.#=zMYVqebM=(#=zdMqiXnPUKtcUXegf4c2kcwWBpiho #=z0cZEudsmNI8e)
at #=zkr25Du_dEy8w3gcs91eEkuo=.#=zU5MWqmY=(#=zdMqiXnPUKtcUXegf4c2kcwWBpiho #=z0cZEudsmNI8e)
at #=qjrpJuo1_FRjl_sVBWiWObADgzsOzryqiDMqs_BfgySU=.#=zlvslZl61KO8a4s55C0uiPmFhggNycT9pOWpxpr2EK_Me(Object #=zWTWpUv4=)
at #=qjrpJuo1_FRjl_sVBWiWObADgzsOzryqiDMqs_BfgySU=.#=z_rrAp8Ks6eldYiJfLB6d$ck=(MethodBase #=zWTWpUv4=, Boolean #=z50CXgO8=)
at #=qjrpJuo1_FRjl_sVBWiWObADgzsOzryqiDMqs_BfgySU=.#=z1a3$NwrSE90bgE1fRH9u2NTZVl5DQwLAHQ==(#=qjrpJuo1_FRjl_sVBWiWObADgzsOzryqiDMqs_BfgySU= #=zWTWpUv4=, #=qcZU62hg7pO6WlojczB5Hvi8rftQngSyInkVU2M6z8Lg= #=z50CXgO8=)
at #=qjrpJuo1_FRjl_sVBWiWObADgzsOzryqiDMqs_BfgySU=.#=zjkSuTuztIcQPH$CRIiLOJ7EB9XgUnS7xwIUsbx4=()
at #=qjrpJuo1_FRjl_sVBWiWObADgzsOzryqiDMqs_BfgySU=.#=zGEhHqzRFPi10vGTtMVCkKFY6hGFItuKNjPmivhU=(Boolean #=zWTWpUv4=)
at #=qjrpJuo1_FRjl_sVBWiWObADgzsOzryqiDMqs_BfgySU=.#=zlvslZl61KO8a4s55C0uiPmFhggNycT9pOWpxpr2EK_Me(Object #=zWTWpUv4=)
at #=qjrpJuo1_FRjl_sVBWiWObADgzsOzryqiDMqs_BfgySU=.#=za3E6YyZ$mzmjJyFQDGy5Tqu4044YRNR_Kw==()
at #=qjrpJuo1_FRjl_sVBWiWObADgzsOzryqiDMqs_BfgySU=.#=z6Sj1nq1f1NPLBAJnNlRDbGX$r9E5z_L02Ue5hNQ=(#=qjrpJuo1_FRjl_sVBWiWObADgzsOzryqiDMqs_BfgySU= #=zWTWpUv4=, #=qcZU62hg7pO6WlojczB5Hvi8rftQngSyInkVU2M6z8Lg= #=z50CXgO8=)
at #=qjrpJuo1_FRjl_sVBWiWObADgzsOzryqiDMqs_BfgySU=.#=zjkSuTuztIcQPH$CRIiLOJ7EB9XgUnS7xwIUsbx4=()
at #=qjrpJuo1_FRjl_sVBWiWObADgzsOzryqiDMqs_BfgySU=.#=zGEhHqzRFPi10vGTtMVCkKFY6hGFItuKNjPmivhU=(Boolean #=zWTWpUv4=)
at #=qjrpJuo1_FRjl_sVBWiWObADgzsOzryqiDMqs_BfgySU=.#=zlvslZl61KO8a4s55C0uiPmFhggNycT9pOWpxpr2EK_Me(Object #=zWTWpUv4=)
at #=qjrpJuo1_FRjl_sVBWiWObADgzsOzryqiDMqs_BfgySU=.#=za3E6YyZ$mzmjJyFQDGy5Tqu4044YRNR_Kw==()
at #=qjrpJuo1_FRjl_sVBWiWObADgzsOzryqiDMqs_BfgySU=.#=z6_UIxvi9hEdkec0z_RdgW47J3ZrezItoCw==(Object #=zWTWpUv4=, UInt32 #=z50CXgO8=)
at #=qjrpJuo1_FRjl_sVBWiWObADgzsOzryqiDMqs_BfgySU=.#=zGEhHqzRFPi10vGTtMVCkKFY6hGFItuKNjPmivhU=(Boolean #=zWTWpUv4=)
at #=qjrpJuo1_FRjl_sVBWiWObADgzsOzryqiDMqs_BfgySU=.#=zGEhHqzRFPi10vGTtMVCkKFY6hGFItuKNjPmivhU=(Boolean #=zWTWpUv4=)
at #=qjrpJuo1_FRjl_sVBWiWObADgzsOzryqiDMqs_BfgySU=.#=zD05HGW5DCVdTXFkfi9G$OT8=()
at #=qjrpJuo1_FRjl_sVBWiWObADgzsOzryqiDMqs_BfgySU=.#=zpmcPhfIWD46BmxQrI4eMHe_ChDxI(Object[] #=zWTWpUv4=, Type[] #=z50CXgO8=, Type[] #=zuKE89C0=, Object[] #=zXVhg$dM=)
at #=qjrpJuo1_FRjl_sVBWiWObADgzsOzryqiDMqs_BfgySU=.#=zsQ6p0VEKaBGQB_avvjxSPSg=(Stream #=zWTWpUv4=, String #=z50CXgO8=, Object[] #=zuKE89C0=, Type[] #=zXVhg$dM=, Type[] #=zo6EU_SM=, Object[] #=zVl9bPOs=)
at #=qjrpJuo1_FRjl_sVBWiWObADgzsOzryqiDMqs_BfgySU=.#=zTtnUdUi984CGQdJ8QvAeoxs1o10v(Stream #=zWTWpUv4=, String #=z50CXgO8=, Object[] #=zuKE89C0=)
at #=qjrpJuo1_FRjl_sVBWiWObADgzsOzryqiDMqs_BfgySU=.#=z7VlsZjp9TBBfeiQa$awM6I8=(Stream #=zWTWpUv4=, String #=z50CXgO8=, Object[] #=zuKE89C0=)
at Aspose.Pdf.Document.#=ztbgZETxyyNb1(Stream #=zatgLNjc=, SaveOptions #=zedgK6GAL_Xpb)
at Aspose.Pdf.Document.#=zMcBHkfdIEOVQ(String #=zgtF84jMtp8CE)
at Aspose.Pdf.Document.Save(String outputFileName)
at PDFtoPDFA3b.Program.Main(String[] args) in /Users/davisb1/Code/aspose/PDFtoPDFA3b/Program.cs:line 21

Anyone else running Aspose on .net core 3.1?

@brianaspose,

Can you please share source file along with sample project and complete environment details so that we may further investigate to help you out.

The Aspose PDFToPDFA sample is as follows:

using System;
using System.IO;
using Aspose.Pdf;

namespace PDFtoPDFA3b
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(“Hello World!”);
string dataDir = @“./pdf/”;

        // Open document
        Document pdfDocument = new Document(dataDir + "input.pdf");            
        
        pdfDocument.Convert(new MemoryStream(), PdfFormat.PDF_A_3B, ConvertErrorAction.Delete);

        dataDir = dataDir + "PDFToPDFA3b_out.pdf";
        // Save output document
        pdfDocument.Save(dataDir);
        // ExEnd:PDFToPDFA3b
        Console.WriteLine("\nPDF file converted to PDF/A-3B format.\nFile saved at " + dataDir);
    }
}

}

The OS is macOS Mojave 10.14.6
.Net Core 3.1.101

I’ve tried the same project on a Windows 10 machine (same version of .net core) and it works fine. Seems to be Aspose on .Net Core 3.1 Mac that doesn’t work.

@brianaspose,

Can you please share source PDF file so that we may further investigate to help you out.

Any PDF will do…I’ve attached one of the pdf samples from Aspose
input.pdf (153.4 KB)

@brianaspose,

I have observed issue you mentioned and have logged it as PDFNET-47776 in our issue tracking system. We will further look into details of the issue and keep you posted with the status of its correction. Please be patient and spare us little time.

We are sorry for the inconvenience.

Hi Adnan - I retried this simple project with .NET Standard 2.0 (.NET Core 2.0/2.1) per the supported frameworks System Requirements|Aspose.PDF for .NET in case the issue was caused by using a current version of .net core. The bug was reproducible. Being able to save a PDF is such a basic function for a PDF library that I wonder if any test cases have been run on Mac at all? I don’t think Aspose should be advertising compatibility with Mac if such a basic example hasn’t been tested. As this bug makes the library useless for Mac .Net users will PDFNET-47776 be given the high-priority required to be fixed in a short period of time?

@brianaspose,

I like to inform that your concerns are being taken care of and we are investigating your issue. Can you please confirm if libgdiplus package is installed on your side and all MS Core fonts are there.

Thanks for the feedback. I checked the libgdiplus situation but I was already up to date:

brew install mono-libgdiplus
Warning: mono-libgdiplus 6.0.4_1 is already installed and up-to-date

The MS Core fonts was a new one to me. However I did have MS Office installed so I did the following:

mkdir ~/Library/Fonts/Microsoft
cp -av /Applications/Microsoft\ Word.app/Contents/Resources/Fonts/* ~/Library/Fonts/Microsoft/

I then modified the sample to include the new font folder before doing the processing:

string fontFolderPath = “~/Library/Fonts/Microsoft/”;
FolderFontSource fs = new FolderFontSource(fontFolderPath);
FontRepository.Sources.Add(fs);

Is that what you meant? The code lines above run successfully but it didn’t make a difference to the ability to save - it still failed with a null reference exception.

@brianaspose,

Thanks for sharing requested information with us. We have mentioned this in our issue tracking system and will share good news with you soon.

Hi @adnanahmed,

Is there any update on this issue ? This has been a blocker for a very long time. Please share some updates if you have.

Thanks

@ankurspotdraft

We would like to share with you that investigation against your issue is currently underway. However, it is not yet completed. We have recorded your concerns and will surely consider them during the analysis and implementing the fix of the issue. Please have patience and give us some time.

We apologize for the inconvenience.