I am working on a .Net Standard 2.0 Class library which will be used in a .NET 4.7.2 application. Both projects are in the same solution. The library uses Aspose.Words to generate a document and save it in PDF format. We would like to use .Net Standard 2.0 to be future proof.
I referenced Aspose.Words (23.7.0) package on the library using Nuget. I use <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
in my library .csproj file to avoid referencing Aspose.Words in my Console application.
First, I get an error when trying to save a document in a PDF stream using
doc.Save(ms, SaveFormat.Pdf);
I get following exception:
System.NullReferenceException: 'Object reference not set to an instance of an object.'
Then when I use SkiaSharp, I get following exception:
System.TypeInitializationException
HResult=0x80131534
Message=The type initializer for 'SkiaSharp.SKImageInfo' threw an exception.
Source=SkiaSharp
StackTrace:
at SkiaSharp.SKImageInfo..ctor(Int32 width, Int32 height)
at AsposeWord.WordTemplate.TestSkiaSharp() in
[path]\AsposeForum\AsposeWord\WordTemplate.cs:line 50
at AsposeWordTest.Program.Main(String[] args) in
[path]\AsposeForum\AsposeWordTest\Program.cs:line 48
This exception was originally thrown at this call stack:
SkiaSharp.SKImageInfo.SKImageInfo()
Inner Exception 1:
DllNotFoundException: Unable to load DLL 'libSkiaSharp': Le module spécifié est introuvable.
(Exception from HRESULT: 0x8007007E)
I think it’s related to the SkiaSharp and Aspose.Words.PDF dll versions copied to my console project because if I integrate the library code in the console application it works as expected.
I prepared a sample solution with both projects (console + library) to illustrate the 2 issues: AsposeForum.zip (86.1 KB)