SkiaSharp
SkiaSharp copied to clipboard
Unable to load shared library 'libSkiaSharp' exception occurs using DOT NET 8 AWS Lambda
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
- [x] I agree to follow this project's Code of Conduct
Got the same issue on Debian GNU/Linux 12 (bookworm), .NET8, and SkiaSharp 2.88.6.
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.
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.
Same issue on AWS Lambda with .NET8. Haven't tried .NET6.
I am testing here with AWS and it works for me: https://github.com/mattleibow/SkiaSharpAwsLambda
I am using the SkiaSharp.NativeAssets.Linux.NoDependencies package to avoid having to install OS dependencies. If you don't want this one, then you will have to use the docker containers.
I have included both examples in the repo.
Hi @pandi123. We have added the status/needs-info label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.
This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment. If it is closed, feel free to comment when you are able to provide the additional information and we will re-investigate.