Docker环境下使用SkiaSharp出现如下错误:
Message: The type initializer for 'SkiaSharp.SKData' threw an exception. StackTrace: at SkiaSharp.SKData.Create(Stream stream)
at SkiaSharp.SKImage.FromEncodedData(Stream data)
解决方法:
方案1:
Dockerfile使用正常的底包:mcr.microsoft.com/dotnet/aspnet:5.0
项目引用SkiaSharp与SkiaSharp.NativeAssets.Linux.NoDependencies这两个nuget包即可。
Dockfile:
FROM mcr.microsoft.com/dotnet/aspnet:5.0
WORKDIR /app
COPY published .
ENTRYPOINT ["dotnet", "xxx.dll"]
方案2:
1、项目引用SkiaSharp与SkiaSharp.NativeAssets.Linux这两个nuget包
2、重新制作镜像底包,命名为:aspnet:5.0-skiasharp
docker build -t aspnet:5.0-skiasharp .
底包相应Dockfile:
FROM mcr.microsoft.com/dotnet/aspnet:5.0
RUN apt-get update && apt-get install -y libfontconfig1
3、制作应用镜像包
Dockerfile:
FROM aspnet:5.0-skiasharp
WORKDIR /app
COPY published .
ENTRYPOINT ["dotnet", "xxx.dll"]