.NET Core 6部署Ubuntu 20.04时libSkiaSharp加载失败求助
.NET Core 6部署Ubuntu 20.04后SkiaSharp无法加载libSkiaSharp共享库问题
开发的.NET Core 6应用在Windows 11本地运行正常,部署到Ubuntu 20.04服务器后,调用SkiaSharp时触发无法加载libSkiaSharp共享库的错误。已尝试以下方案均未解决:
- 更换SkiaSharp.NativeAssets系列包
- 调整发布目标运行时(Portable/linux-x64)
- 手动移动库文件位置
- 安装libfontconfig1
- 检查库文件依赖与权限
错误信息
Linux环境调用SkiaSharp时触发如下错误:
[错误日志截图]
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
补充细节
- 项目通过SKTypeFace使用SkiaSharp处理文本,先后尝试
SkiaSharp.NativeAssets.Linux与SkiaSharp.NativeAssets.Linux.NoDependencies包,均无效;未触发SKTypeFace相关代码时仍报错。 - 已确认项目引用包([项目引用包截图])
- 已检查
libSkiaSharp.so文件权限([权限检查截图]),权限配置正常 - 使用
ldd命令验证库文件依赖,显示所有依赖均已存在([ldd依赖检查截图]) - 已安装
libfontconfig1包
内容的提问来源于stack exchange,提问作者Rudazzle
相关产品推荐
相关产品推荐

