I've built a .NET Core 6 application that runs without issue on my local Windows 11 machine. I've deployed it to an Ubuntu 20.04 server and I receive an error that it cannot load the libSkiaSharp shared library. I've seen other people report this issue but none of the suggestions are working for me.
Error
Error is received whenever SkiaSharp is used via code in a Linux environment
Feb 9 19:40:10 vmi1190349 dotnet-MyTest[9456]: System.TypeInitializationException: The type initializer for 'SkiaSharp.SKData' threw an exception. <e LD_DEBUG environment variable: liblibSkiaSharp: cannot open shared object file: No such file or directory Feb 9 19:40:10 vmi1190349 dotnet-MyTest[9456]: fail: MyTest.Controllers.MyController[0] Feb 9 19:40:10 vmi1190349 dotnet-MyTest[9456]: The type initializer for 'SkiaSharp.SKData' threw an exception. Feb 9 19:40:10 vmi1190349 dotnet-MyTest[9456]: System.TypeInitializationException: The type initializer for 'SkiaSharp.SKData' threw an exception. Feb 9 19:40:10 vmi1190349 dotnet-MyTest[9456]: ---> System.DllNotFoundException: Unable to load shared library 'libSkiaSharp' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: liblibSkiaSharp: cannot open shared object file: No such file or directory Feb 9 19:40:10 vmi1190349 dotnet-MyTest[9456]: at SkiaSharp.SkiaApi.sk_data_new_empty() Feb 9 19:40:10 vmi1190349 dotnet-MyTest[9456]: at SkiaSharp.SKData..cctor() Feb 9 19:40:10 vmi1190349 dotnet-MyTest[9456]: --- End of inner exception stack trace --- Feb 9 19:40:10 vmi1190349 dotnet-MyTest[9456]: at SkiaSharp.SKData.Create(IntPtr address, Int32 length) Feb 9 19:40:10 vmi1190349 dotnet-MyTest[9456]: at SkiaSharp.SKBitmap.Decode(ReadOnlySpan`1 buffer) Feb 9 19:40:10 vmi1190349 dotnet-MyTest[9456]: at SkiaSharp.SKBitmap.Decode(Byte[] buffer) Feb 9 19:40:10 vmi1190349 dotnet-MyTest[9456]: at Test.Common.Image.ImageManager.GenerateImage(ImageOptions MyPost, Details details) in C:\Users\TestUser\source\repos\Test.Web.Main\Test.Common.Image\ImageManager.cs:line 109 Feb 9 19:40:10 vmi1190349 dotnet-MyTest[9456]: at MyTest.Controllers.MyController.Get(ImageOptions MyPost) in C:\Users\TestUser\source\repos\Test.Web.Main\MyTest\Controllers\MyController.cs:line 84
Additional Details
I use SkiaSharp with text via SKTypeFace so I believe I need the SkiaSharp.NativeAssets.Linux package. However, after trying other suggestions and those not working, I removed the package and installed SkiaSharp.NativeAssets.Linux.NoDependencies. I'm still receiving the error though. My application takes user input to determine how SkiaSharp is used so I'm not hitting any code that is using SKTypeFace and I'm still receiving the same error while using the NoDependencies package.
My project has references to the following packages:
I initially published the application with Target-Runtime = Portable but that didn't work. I tried moving the LibSkiaSharp.so file from the Runtimes directory to my web applications directory and that didn't work. I've also tried updating my publish settings to Target-Runtime=linux-x64 as this puts all of the project files in the root directory, redeployed, restarted the apache server and still receive the error.
Here are the file permissions for the deployed libSkiaSharp.so:
I've run the ldd command and it appears to have all of the necessary dependencies for libSkiaSharp.so.
I've also run the command to install libfontconfig1 as well