Hello.
While hosting aspose on dotnetcore3.1 in an Alpine based container I get the following error message when converting any type of Aspose files (I have tried both Words and Cells):
System.NullReferenceException: Object reference not set to an instance of an object.
\n at .(Type )\n at .(Object[] )\n at .(Object[] , Type[] , Type[] , Object[] \b)\n at .(Stream , String , Object[] , Type[] \b, Type[] , Object[] )\n at .(Stream , String , Object[] )\n at .(Stream , String , Object[] )\n at Aspose.Words.License.SetLicense(Stream stream)\n at AsposeLinuxTest.FileConverter.API_Aspose.AsposeFileConverter.SetAsposeLicense(DocumentType docType)\n at AsposeLinuxTest.FileConverter.API_Aspose.AsposeFileConverter.ConvertWordToPdfa(String fileToConvert, String destination, DocumentType doctType)\n at AsposeLinuxTest.FileConverter.API_Aspose.AsposeFileConverter.ConvertToPdfAsync(ConfigWrapper configWrapper, DocumentType docType, String fileToConvert, String destination, Int32 recursionLevel)\n
When hosting on Windows the same project, it works fine.
I have googled some topics, so I have added some extra code, but note that these changes did not change the error message in any way.
Conversion code:
private static void ConvertWordToPdfaLinux(string fileToConvert, string destination, Stream licenseStream)
{
var wordLicense = new Aspose.Words.License();
wordLicense.SetLicense(licenseStream);
var doc = new Aspose.Words.Document(fileToConvert);
doc.FontSettings.SetFontsFolder("/fonts", true); // This folder contains font used in the document
var options = new Aspose.Words.Saving.PdfSaveOptions
{
SaveFormat = Aspose.Words.SaveFormat.Pdf,
Compliance = Aspose.Words.Saving.PdfCompliance.PdfA1b,
ExportDocumentStructure = true // This will include Structured Document Tags (SDT) in the PDF.
};
doc.Save(destination, options);
}
Alpine Linux container creation relevant code:
…
COPY fonts/ /fonts
RUN apk add libgdiplus --repository Index of /alpine/edge/testing/ --allow-untrusted
RUN ln -s libgdiplus.so /app/gdiplus.dll
WORKDIR /app
…
After starting up the container:
- The “/fonts” folder contains .ttf files of the font.
- The “/app” folder contains all dotnetcore3.1 files + the program + the “gdiplus.dll” file we created.
- I have made sure the path to fileToConvert and destination is correct Linux format and the fileToConvert exists when entering the method
Any suggestions on how to fix this issue?
EDIT additional clarifying info:
The content of the “/app” folder is the result of running a dotnet publish that is selfcontained and targeting linux-musl-x64. This is something I have a lot of experience with in other containers with same setup. Command ran:
dotnet publish Source/AsposePdfConverter.csproj --configuration Release -p:MvcRazorCompileOnPublish=false --runtime linux-musl-x64 --self-contained=true /p:PackageAsSingleFile=false /p:PublishTrimmed=true --output Source/AsposePdfConverter/bin/Release/PublishOutput/Linux/AsposePdfConverter
The content of the PublishOutput/Linux/AsposePdfConverter folder is then copied into the “/app” folder in the container.
In order to be able to run dotnet publish in this way, I had to also add the following extra references:
PackageReference Include=“System.Collections” Version=“4.3.0” />
PackageReference Include=“System.Diagnostics.Debug” Version=“4.3.0” />
PackageReference Include=“System.IO.FileSystem.Primitives” Version=“4.3.0” />
PackageReference Include=“System.Runtime.Extensions” Version=“4.3.1” />
PackageReference Include=“System.Runtime.Handles” Version=“4.3.0” />
PackageReference Include=“System.Runtime.InteropServices” Version=“4.3.0” />
Version of Aspose.Words = 19.9.0
Version of Aspose.Cells = 19.8.0