SkiaSharp throw exception


#1

Hi,
I’m trying to create a simple word document form html and save to docx and pdf.
.NET Core 2.0 on console application works fine, but on a api controller .NET Core 2.0 only save docx run successfully. Save to pdf give me an error.
The code is very simple

public byte[] Render(string html)
{
    var doc = new Document();
    var builder = new DocumentBuilder(doc);
    builder.Writeln("Random text");
    builder.InsertHtml(html);

    var msResult = new MemoryStream();
    doc.Save(msResult, SaveFormat.Docx);

    doc.Save(@"C:\temp\aspose.docx", SaveFormat.Docx);
    doc.Save(@"C:\temp\aspose.pdf", SaveFormat.Pdf);  //<-- this line throw exception

    msResult.Position = 0;
    return msResult.ToArray();
}

And this is the error:

The type initializer for ‘SkiaSharp.SKAbstractManagedStream’ threw an exception.
System.TypeInitializationException: The type initializer for ‘SkiaSharp.SKAbstractManagedStream’ threw an exception. —> System.DllNotFoundException: Unable to load DLL ‘libSkiaSharp’: Impossibile trovare il modulo specificato. (Exception from HRESULT: 0x8007007E)
at SkiaSharp.SkiaApi.sk_managedstream_set_delegates(IntPtr pRead, IntPtr pPeek, IntPtr pIsAtEnd, IntPtr pHasPosition, IntPtr pHasLength, IntPtr pRewind, IntPtr pGetPosition, IntPtr pSeek, IntPtr pMove, IntPtr pGetLength, IntPtr pCreateNew, IntPtr pDestroy)
at SkiaSharp.SKAbstractManagedStream…cctor()
— End of inner exception stack trace —
at SkiaSharp.SKAbstractManagedStream…ctor(Boolean owns)
at SkiaSharp.SKManagedStream…ctor(Stream managedStream, Boolean disposeManagedStream, Boolean owns)
at SkiaSharp.SKManagedStream…ctor(Stream managedStream, Boolean disposeManagedStream)
at SkiaSharp.SKBitmap.WrapManagedStream(Stream stream)
at SkiaSharp.SKBitmap.Decode(Stream stream)…

Can you help me?
Thank you.


#2

@ivanosw1,

Please remove Aspose.Words and SkiaSharp references from your project and Clean it. And then do a fresh installation of latest version of Aspose.Words for .NET i.e. 18.7 from NuGet. In Visual Studio for Windows, select the Tools > NuGet Package Manager > Manage NuGet Packages for Solution… menu command, or right-click the solution and select Manage NuGet Packages… Search for Aspose.Words package under Browser tab and install it. Rebuilding the project again should resolve this issue. Hope, this helps.


#3

Thank you awais.hafeez.
What you say is exactly what I’ve done.
I’m using Aspose.Word 18.7 and related SkiaSharp 1.60.0

The problem happens only in a .net Core 2.0 web application.
.Net Core 2.0 console application works fine.

Can you provide me a link of a asp.net core 2.0 application?
Thank you.


#4

@ivanosw1,

We are still unable to reproduce this issue on our end. Please see this sample .NET Core 2.0 Web Application. NetCoreWebApp.zip (806.0 KB)


#5

Thank you @awais.hafeez
I found the problem.
In the deployment process, the folder runtimes was not update.


#6

@ivanosw1,

It is great that you were able to resolve this issue on your end. Please let us know anytime you have any further queries.