Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to load shared library 'libSkiaSharp' exception occurs using DOT NET 8 AWS Lambda #2961

Open
1 task done
pandi123 opened this issue Jul 30, 2024 · 3 comments
Open
1 task done
Labels

Comments

@pandi123
Copy link

pandi123 commented Jul 30, 2024

Description

We have created the SKBitmap and drawn a rectangle, circle, and line in .NET using AWS Lambda. We encountered an issue while using SkiaSharp.NativeAssets.Linux NuGet in an AWS Lambda - we faced the 'Unable to load shared library 'libSkiaSharp' exception. However, this issue does not occur when using .NET6 AWS Lambda.

Platform: AWS Lambda
Visual Studio version: 2022
.NET version : .NET8
SkiaSharp version : 2.88.6

Code

The best way to share code for larger projects is a link to a GitHub repository: https://github.com/user/repo/tree/bug-123

But, you can also share a short block of code here:

public string FunctionHandler( ILambdaContext context)
{
     //Define the image dimensions
     int width = 800;
     int height = 600;
     string base64String;
 
     //Create a new bitmap
     using (var bitmap = new SKBitmap(width, height))
     {
         // Create a canvas to draw on the bitmap
         using (var canvas = new SKCanvas(bitmap))
         {
             // Clear the canvas with a white color
             canvas.Clear(SKColors.White);
 
             // Define the paint for drawing shapes
             var paint = new SKPaint
             {
                 Color = SKColors.Blue,
                 IsAntialias = true,
                 Style = SKPaintStyle.Stroke,
                 StrokeWidth = 5
             };
 
             // Draw a rectangle
             var rect = new SKRect(100, 100, 300, 300);
             canvas.DrawRect(rect, paint);
 
             // Draw a circle
             paint.Color = SKColors.Red;
             canvas.DrawCircle(400, 400, 100, paint);
 
             // Draw a line
             paint.Color = SKColors.Green;
             canvas.DrawLine(500, 100, 700, 300, paint);
 
             // Save the bitmap to a file
             using (var image = SKImage.FromBitmap(bitmap))
             using (var data = image.Encode(SKEncodedImageFormat.Png, 100))
 
             using (var memoryStream = new MemoryStream())
             {
                 data.SaveTo(memoryStream);
                 byte[] imageBytes = memoryStream.ToArray();
                 base64String = Convert.ToBase64String(imageBytes);
                 Console.WriteLine(base64String);
 
                 // Print or return the base64 string
             }
         }
     }
     return base64String;
}
// some C# code here

You can also share some XAML:

<!-- xaml code here -->

Expected Behavior

The program should run without any exceptions in AWS Lambda .NET8

Actual Behavior

Get an exception is .NET version 8
Working fine in .NET version 6

System.DllNotFoundException: Unable to load shared library 'libSkiaSharp' or one of its dependencies. In order to help diagnose loading problems, consider using a tool like Strace. If you're using glibc, consider setting the LD_DEBUG environment variable.

Version of SkiaSharp

Other (Please indicate in the description)

Last Known Good Version of SkiaSharp

2.88.2 (Previous)

IDE / Editor

Visual Studio (Windows)

Platform / Operating System

Windows

Platform / Operating System Version

Windows 11

Devices

Asus 12th Gen Intel(R) Core(TM) i5-1235U 1.30 GHz

Relevant Screenshots

No response

Relevant Log Output

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@2mik
Copy link

2mik commented Aug 6, 2024

Got the same issue on Debian GNU/Linux 12 (bookworm), .NET8, and SkiaSharp 2.88.6.

@2mik
Copy link

2mik commented Aug 7, 2024

In my case sudo apt install libfontconfig1 solved the issue. But the error message (in the page title) is not clear for that purpose. See this thread.

@iharmaiseyeu
Copy link

I have the same issue after moving Linux Azure Functions to .NET 8. Everything works perfectly fine on .NET 6.

Because it is Azure Function I cannot use sudo apt install libfontconfig1 to install additional dependencies.

The following packages were installed:

<PackageReference Include="SkiaSharp" Version="2.88.8" />
<PackageReference Include="SkiaSharp.NativeAssets.Linux.NoDependencies" Version="2.88.8" />

There is the solution in the thread #1341 but it looks mostly like a workaround, not like a real fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants