mono / SkiaSharp

SkiaSharp is a cross-platform 2D graphics API for .NET platforms based on Google's Skia Graphics Library. It provides a comprehensive 2D API that can be used across mobile, server and desktop models to render images.
MIT License
4.4k stars 535 forks source link

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

Open pandi123 opened 1 month ago

pandi123 commented 1 month ago

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:

{
     //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

2mik commented 1 month ago

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

2mik commented 1 month ago

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 commented 2 weeks ago

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.