Skiasharp: Unable to load DLL 'libSkiaSharp' on Linux (AWS Lambda)

Created on 2 May 2017  路  23Comments  路  Source: mono/SkiaSharp

I used to have a 1.56.2 build (pull date arround 2017-03-01) I compiled that on a Linux (Ubuntu 16.04) box. And that version worked perfectly fine on AWS Lambda and also on other Linux boxes.

Now I have compiled againt the latest source 1.57.1 (checkout 2017-05-02) and no matter what I try I get

System.TypeInitializationException: The type initializer for 'SkiaSharp.SKManagedStream' threw an exception. ---> System.DllNotFoundException: Unable to load DLL 'libSkiaSharp': The specified module could not be found.

Is there something I'm doing wrong. Has something significantly changed the way it used to load the native lib.

BTW: I included libSkiaSharp.so and libSkiaSharp.so.57.1.0 in the bin dir.

os-Linux

All 23 comments

Could this be a result of differing architectures? The library could be x86 but the machine is x64, or vice versa.

The only real requirement for linux is that libSkiaSharp.so be in the same directory as SkiaSharp.dll.

If you run ./bootstrapper.sh -t tests on your build machine, does that work?

Hi @mattleibow I was always using the X64 version, the same way I used the 1.56.2 build.

This is the output for the unit test. (It seems that only the X tests failed. Since it's a Linux box without X installed.)

Test Files
    /home/ubuntu/Projects/SkiaSharp/tests/SkiaSharp.NetCore.Tests.Runner/artifacts/SkiaSharp.NetCore.Tests.dll

Tests Not Run

1) Ignored : SkiaSharp.Tests.SKBitmapTest.ImageScalingMultipleThreadsTest
This test takes a long time (~3mins), so ignore this most of the time.

2) Ignored : SkiaSharp.Tests.SKDataTest.DataDisposedReturnsInvalidStream
Doesn't work as it relies on memory being overwritten by an external process.

3) Ignored : SkiaSharp.Tests.SKPathTest.TightBoundsForEnclosedPathIsNotZero
Known to fail, see: https://groups.google.com/forum/#!topic/skia-discuss/bhQCWsmARzo

Errors, Failures and Warnings

1) Error : SkiaSharp.Tests.GRContextTest.CreateDefaultContextIsValid
System.Exception : Failed to open X display.
   at SkiaSharp.Tests.GlxContext..ctor() in /home/ubuntu/Projects/SkiaSharp/tests/Tests/GlContexts/Glx/GlxContext.cs:line 43
   at SkiaSharp.Tests.SKTest.CreateGlContext() in /home/ubuntu/Projects/SkiaSharp/tests/Tests/SKTest.cs:line 95
   at SkiaSharp.Tests.GRContextTest.CreateDefaultContextIsValid() in /home/ubuntu/Projects/SkiaSharp/tests/Tests/GRContextTest.cs:line 13

2) Error : SkiaSharp.Tests.GRContextTest.CreateSpecificContextIsValid
System.Exception : Failed to open X display.
   at SkiaSharp.Tests.GlxContext..ctor() in /home/ubuntu/Projects/SkiaSharp/tests/Tests/GlContexts/Glx/GlxContext.cs:line 43
   at SkiaSharp.Tests.SKTest.CreateGlContext() in /home/ubuntu/Projects/SkiaSharp/tests/Tests/SKTest.cs:line 95
   at SkiaSharp.Tests.GRContextTest.CreateSpecificContextIsValid() in /home/ubuntu/Projects/SkiaSharp/tests/Tests/GRContextTest.cs:line 25

3) Error : SkiaSharp.Tests.GRGlInterfaceTest.AssembleInterfaceIsValid
System.Exception : Failed to open X display.
   at SkiaSharp.Tests.GlxContext..ctor() in /home/ubuntu/Projects/SkiaSharp/tests/Tests/GlContexts/Glx/GlxContext.cs:line 43
   at SkiaSharp.Tests.SKTest.CreateGlContext() in /home/ubuntu/Projects/SkiaSharp/tests/Tests/SKTest.cs:line 95
   at SkiaSharp.Tests.GRGlInterfaceTest.AssembleInterfaceIsValid() in /home/ubuntu/Projects/SkiaSharp/tests/Tests/GRGlInterfaceTest.cs:line 27

4) Error : SkiaSharp.Tests.GRGlInterfaceTest.CreateDefaultInterfaceIsValid
System.Exception : Failed to open X display.
   at SkiaSharp.Tests.GlxContext..ctor() in /home/ubuntu/Projects/SkiaSharp/tests/Tests/GlContexts/Glx/GlxContext.cs:line 43
   at SkiaSharp.Tests.SKTest.CreateGlContext() in /home/ubuntu/Projects/SkiaSharp/tests/Tests/SKTest.cs:line 95
   at SkiaSharp.Tests.GRGlInterfaceTest.CreateDefaultInterfaceIsValid() in /home/ubuntu/Projects/SkiaSharp/tests/Tests/GRGlInterfaceTest.cs:line 14

5) Error : SkiaSharp.Tests.SKTypefaceTest.TestFontManagerMatchCharacter
System.NullReferenceException : Object reference not set to an instance of an object.
   at SkiaSharp.Tests.SKTypefaceTest.TestFontManagerMatchCharacter() in /home/ubuntu/Projects/SkiaSharp/tests/Tests/SKTypefaceTest.cs:line 108

Run Settings
    Work Directory: /home/ubuntu/Projects/SkiaSharp
    Internal Trace: Off

Test Run Summary
  Overall result: Failed
  Test Count: 94, Passed: 86, Failed: 5, Warnings: 0, Inconclusive: 0, Skipped: 3
    Failed Tests - Failures: 0, Errors: 5, Invalid: 0
    Skipped Tests - Ignored: 3, Explicit: 0, Other: 0
  Start time: 2017-05-08 21:49:21Z
    End time: 2017-05-08 21:49:27Z
    Duration: 5.359 seconds

Results (nunit3) saved as /home/ubuntu/Projects/SkiaSharp/TestResult.xml

This is totally weird. Basically, this is a .NET Core app that is being published - and it runs.

This folder: /home/ubuntu/Projects/SkiaSharp/tests/SkiaSharp.NetCore.Tests.Runner/artifacts/ should contain a executable along with SkiaSharp.dll and libSkiaSharp.so (and stacks of other .NET assemblies). If you run the executable (I think it is ./SkiaSharp.NetCore.Tests.Runner), then the test should run - this is a plain old .NET app.

If you take the output SkiaSharp.dll and libSkiaSharp.so files and write your own app, it should run on the same machine - because it just did. But if you create a new app, and then just reference the managed assembly and copy the native, does that work?

@wcrooy Try build from this package - https://www.nuget.org/packages/Avalonia.Skia.Linux.Natives
It works for me on Ubuntu 15.10. Also try to use ldd to check if there is some missing native dependency.

@kekekeks thanks for your effort in getting the builds out!

@wcrooy I forgot to ask, are you using .NET Core to run your app, or is this the Full Mono stack?

@kekekeks it is strange that his machine can run the .NET Core tests, but his app does not work... Technically, if this is a dependency issue, nothing should have worked.

@kekekeks I'll try that one as well.

@mattleibow I'm using .NET Core 1.0.x

I'll try to create a small reproduceable package/console app asap.

@wcrooy @kekekeks I can confirm I have the same issue. The Avalonia compiled natives for linux x64 don't help; they used to.

@shravan2x @wcrooy I am not able to repro this. I am running Ubuntu 14.04 and this works.
AvaloniaTest.zip

I just did dotnet restore && dotnet run.

@kekekeks I had a look at your dependencies, and you have this:

    libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0
    libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2
    libfontconfig.so.1 => /usr/lib/x86_64-linux-gnu/libfontconfig.so.1
        libfreetype.so.6 => /usr/lib/x86_64-linux-gnu/libfreetype.so.6
            libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1
            libpng12.so.0 => /lib/x86_64-linux-gnu/libpng12.so.0
        libexpat.so.1 => /lib/x86_64-linux-gnu/libexpat.so.1
    libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6
    libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6
    ld-linux-x86-64.so.2 => /lib/x86_64-linux-gnu/ld-linux-x86-64.so.2

And, I have this:

    libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0
        ld-linux-x86-64.so.2 => /lib/x86_64-linux-gnu/ld-linux-x86-64.so.2
    libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2
    libfontconfig.so.1 => /usr/lib/x86_64-linux-gnu/libfontconfig.so.1
        libfreetype.so.6 => /usr/lib/x86_64-linux-gnu/libfreetype.so.6
            libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1
            libpng12.so.0 => /lib/x86_64-linux-gnu/libpng12.so.0
        libexpat.so.1 => /lib/x86_64-linux-gnu/libexpat.so.1
    libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6
    libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6
    libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6

The difference is that you have a direct dependency on ld-linux-x86-64.so.2, but I do not. Instead I reference libstdc++.so.6.

I'm on Ubuntu 16.04.2 LTS

This is the stack trace:

System.TypeInitializationException: The type initializer for 'SkiaSharp.SKImageInfo' threw an exception. ---> System.DllNotFoundException: Unable to load DLL 'libSkiaSharp': The specified module could not be found.
 (Exception from HRESULT: 0x8007007E)
   at SkiaSharp.SkiaApi.sk_colortype_get_default_8888()
   at SkiaSharp.SKImageInfo..cctor()
   --- End of inner exception stack trace ---

@mattleibow Why can't we have Linux natives baked into the library? If a separate library can support it, surely the SkiaSharp package can?

I have Unable to load DLL 'libSkiaSharp.dll': The specified module could not be found. in Net core Web app running on Windows 2012 R2.

SkiaSharp installed via Nuget. 1.57.1

libSkiaSharp.dll present in app directory on server

System.TypeInitializationException: The type initializer for 'SkiaSharp.SKManagedStream' threw an exception. ---> System.DllNotFoundException: Unable to load DLL 'libSkiaSharp.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)

   at SkiaSharp.SkiaApi.sk_managedstream_set_delegates(IntPtr pRead, IntPtr pPeek, IntPtr pIsAtEnd, IntPtr pRewind, IntPtr pGetPosition, IntPtr pSeek, IntPtr pMove, IntPtr pGetLength, IntPtr pCreateNew, IntPtr pDestroy)

   at SkiaSharp.SKManagedStream..cctor()

   --- End of inner exception stack trace ---

   at SkiaSharp.SKManagedStream..ctor(Stream managedStream)

   at TNPK.Controllers.FormController.GenerateZip(Organization organization)

   at TNPK.Controllers.FormController.<Send>d__15.MoveNext()

--- End of stack trace from previous location where exception was thrown ---

   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)

   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)

   at Microsoft.AspNetCore.Mvc.Internal.ObjectMethodExecutor.<CastToObject>d__38`1.MoveNext()

--- End of stack trace from previous location where exception was thrown ---

   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)

   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)

   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeActionMethodAsync>d__27.MoveNext()

--- End of stack trace from previous location where exception was thrown ---

   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)

   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)

   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeNextActionFilterAsync>d__25.MoveNext()

--- End of stack trace from previous location where exception was thrown ---

   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext context)

   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)

   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeNextResourceFilter>d__22.MoveNext()

--- End of stack trace from previous location where exception was thrown ---

   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ResourceExecutedContext context)

   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)

   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeAsync>d__20.MoveNext()

--- End of stack trace from previous location where exception was thrown ---

   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)

   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)

   at Microsoft.AspNetCore.Builder.RouterMiddleware.<Invoke>d__4.MoveNext()

--- End of stack trace from previous location where exception was thrown ---

   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)

   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)

   at Microsoft.AspNetCore.Localization.RequestLocalizationMiddleware.<Invoke>d__4.MoveNext()

--- End of stack trace from previous location where exception was thrown ---

   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)

   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)

   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware`1.<Invoke>d__18.MoveNext()

--- End of stack trace from previous location where exception was thrown ---

   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware`1.<Invoke>d__18.MoveNext()

--- End of stack trace from previous location where exception was thrown ---

   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)

   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)

   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware`1.<Invoke>d__18.MoveNext()

--- End of stack trace from previous location where exception was thrown ---

   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware`1.<Invoke>d__18.MoveNext()

--- End of stack trace from previous location where exception was thrown ---

   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)

   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)

   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware`1.<Invoke>d__18.MoveNext()

--- End of stack trace from previous location where exception was thrown ---

   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware`1.<Invoke>d__18.MoveNext()

--- End of stack trace from previous location where exception was thrown ---

   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)

   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)

   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware`1.<Invoke>d__18.MoveNext()

--- End of stack trace from previous location where exception was thrown ---

   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware`1.<Invoke>d__18.MoveNext()

--- End of stack trace from previous location where exception was thrown ---

   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)

   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)

   at Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.MigrationsEndPointMiddleware.<Invoke>d__5.MoveNext()

--- End of stack trace from previous location where exception was thrown ---

   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)

   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)

   at Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.DatabaseErrorPageMiddleware.<Invoke>d__6.MoveNext()

--- End of stack trace from previous location where exception was thrown ---

   at Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.DatabaseErrorPageMiddleware.<Invoke>d__6.MoveNext()

--- End of stack trace from previous location where exception was thrown ---

   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)

   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)

   at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.<Invoke>d__7.MoveNext()

As an update to this, the Avalonia 1.57.4 natives work with 1.57. @kekekeks Is there there a Github page for the natives?

Nope, I'm building that library using unmodified script from this repo.

Case: Works on Windows
Fails on Linux docker container.
SkiaSharp installed from Nuget: Install-Package SkiaSharp -Version 1.59.3

Guys, is there any workaround to this issue? Im getting the same error:

System.TypeInitializationException: The type initializer for 'SkiaSharp.SKImageInfo' threw an exception.
 ---> System.DllNotFoundException: Unable to load DLL 'libSkiaSharp': The specified module or one of its dependencies could not be found.
 (Exception from HRESULT: 0x8007007E)
at SkiaSharp.SkiaApi.sk_colortype_get_default_8888()
at SkiaSharp.SKImageInfo..cctor()
--- End of inner exception stack trace ---

My project works on Windows, but when I try to run it from docker container on linux (runtime is on Heroku platform if that matters) I'm receiving above exception.
What I did so far:
First, I tried to change target platform:

dotnet publish --configuration Release --target linux-x64 Solution.sln

  • But, indeed, there is no libSkiaSharp.dll being copied anywhere

I noticed that this file goes to publish folder only when I build from Windows machine (Iin bin\Release\netcoreapp2.0\publish\runtimes\win7-x64\native folder)

I even tried to make this using Makefile executed from Ubuntu machine using files from native folder, but I gave up with solving missing *.h files during make proces :(

I'm wondering if there are already compiled libSkiaSharp linux_x64 bits somewhere that I can grab and reference to project?

@kekekeks Indeed now I see libSkiaSharp.so file in output directory but exception still occurs.... Should I do something more?

Ok, found that I need to apt-install libfontconfig1 to my container. Thanks.

@kekekeks Could you update the Avalonia natives package to 1.59.3?

@dtarczynski you are probably missing libfontconfig2 in your docker image
@shravan2x our process of building the portable binary is a bit tedious and takes quite a bit of time, so I avoid doing that unless absolutely necessary.

@shravan2x we are experimenting with a Linux binary. As it is still in preview, we have just attached it to the release:
https://github.com/mono/SkiaSharp/releases/tag/v1.59.3

Let me know how it goes so that once we feel certain that it will work in most cases, we can add it to the NuGet package.

@mattleibow That's really good to hear. I'll try using this for a while and post back.

I've been using it for about a month, haven't had any issues yet. I'll keep this issue updated if I encounter any problems.

@shravan2x thanks for the feedback!

I am going to close this as I believe that the pre-built native library works (it was built on Ubunto 14.04). Custom Linux distros might need to rebuild.

Was this page helpful?
0 / 5 - 0 ratings