Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The type initializer for 'SkiaSharp.SKImageInfo' threw an exception. #26

Closed
Alex-451 opened this issue Nov 24, 2020 · 21 comments
Closed
Labels
question Further information is requested

Comments

@Alex-451
Copy link

Alex-451 commented Nov 24, 2020

If i build this for linux, i get the error:
The type initializer for 'SkiaSharp.SKImageInfo' threw an exception.
Exception:

 ---> System.DllNotFoundException: Unable to load DLL 'libSkiaSharp' or one of its dependencies: The specified module could not be found. (0x8007007E)
   at SkiaSharp.SkiaApi.sk_colortype_get_default_8888()
   at SkiaSharp.SKImageInfo..cctor()
   --- End of inner exception stack trace ---
   at SkiaSharp.SKImageInfo..ctor(Int32 width, Int32 height)
   at AT.QRCoder.DiscordBot.Commands.QrCoder.GenerateQr(String content, String darkColor, String lightColor, String iconUrl) in C:\Users\Name\Desktop\ProjName\src\Proj.ProjName\Commands\File.cs:line 30```

at this line:
 ` var info = new SKImageInfo(660, 660);`

Do you know what causes that and how to fix that? 
@guitarrapc
Copy link
Owner

thank you for the report.
I've confirm that issue when I was installed old SkiaSharp 1.68. What was your package reference?

samples/ManualGenerate and samples/SimpleGenerate can build with both of following package reference.

  <ItemGroup>
    <PackageReference Include="SkiaSharp.QrCode" Version="0.4.0" />
  </ItemGroup>
  <ItemGroup>
    <PackageReference Include="SkiaSharp" Version="2.80.2" />
    <PackageReference Include="SkiaSharp.NativeAssets.Linux" Version="2.80.2" />
    <PackageReference Include="SkiaSharp.QrCode" Version="0.4.0" />
  </ItemGroup>

linux build log: https://github.com/guitarrapc/SkiaSharp.QrCode/runs/1451161453?check_suite_focus=true

@Alex-451
Copy link
Author

Thanks for the reply, these are my package references:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp3.1</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Discord.Net" Version="2.2.0" />
    <PackageReference Include="Discord.Net.Core" Version="2.2.0" />
    <PackageReference Include="SkiaSharp" Version="2.80.2" />
    <PackageReference Include="SkiaSharp.NativeAssets.Linux" Version="2.80.2" />
    <PackageReference Include="SkiaSharp.QrCode" Version="0.4.0" />
  </ItemGroup>

</Project>```

Unfourtunately it doesnt work. 

@guitarrapc
Copy link
Owner

Ok, I've confirm it reproduce on docker. Let me check.

version: "3"

services:
  netcoreapp3.1:
    image: mcr.microsoft.com/dotnet/core/sdk:3.1
    command: dotnet run --csproj BuildTest.csproj -f netcoreapp3.1
    working_dir: /src
    volumes:
      - ./3.1/:/src

  netcoreapp5.0:
    image: mcr.microsoft.com/dotnet/sdk:5.0
    command: dotnet run --csproj BuildTest.csproj -f net5.0
    working_dir: /src
    volumes:
      - ./5.0:/src
netcoreapp5.0_1  | Unhandled exception. System.TypeInitializationException: The type initializer for 'SkiaSharp.SKImageInfo' threw an exception.
netcoreapp5.0_1  |  ---> 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     
netcoreapp5.0_1  |    at SkiaSharp.SkiaApi.sk_colortype_get_default_8888()
netcoreapp5.0_1  |    at SkiaSharp.SKImageInfo..cctor()
netcoreapp5.0_1  |    --- End of inner exception stack trace ---
netcoreapp5.0_1  |    at SkiaSharp.SKImageInfo..ctor(Int32 width, Int32 height)
netcoreapp5.0_1  |    at SkiaQrCodeSampleConsole.Program.Main(String[] args) in /src/Program.cs:line 22
netcoreapp3.1_1  | Unhandled exception. System.TypeInitializationException: The type initializer for 'SkiaSharp.SKImageInfo' threw an exception.       
netcoreapp3.1_1  |  ---> 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     
netcoreapp3.1_1  |    at SkiaSharp.SkiaApi.sk_colortype_get_default_8888()
netcoreapp3.1_1  |    at SkiaSharp.SKImageInfo..cctor()
netcoreapp3.1_1  |    --- End of inner exception stack trace ---
netcoreapp3.1_1  |    at SkiaSharp.SKImageInfo..ctor(Int32 width, Int32 height)
netcoreapp3.1_1  |    at SkiaQrCodeSampleConsole.Program.Main(String[] args) in /src/Program.cs:line 23

@guitarrapc
Copy link
Owner

guitarrapc commented Nov 25, 2020

temporary workaround, add libfontconfig1 package.

apt update
apt install -y libfontconfig1

This is obvious.... I'm digging into more detail.

@guitarrapc
Copy link
Owner

related.

mono/SkiaSharp#517

@guitarrapc
Copy link
Owner

@guitarrapc
Copy link
Owner

Ok, let's change to SkaiSharp.NativeAssets.Linux.NoDependencies 2.80.2

@guitarrapc
Copy link
Owner

guitarrapc commented Nov 25, 2020

@AlexGipp Can you try with following package?

update: I've released 0.4.1. Please use 0.4.1 and SkiaSharp.NativeAssets.Linux.NoDependencies if you have no dependencies to fonts.

  <ItemGroup>
    <PackageReference Include="SkiaSharp.QrCode" Version="0.4.1" />
    <PackageReference Include="SkiaSharp.NativeAssets.Linux.NoDependencies" Version="2.80.2" />
  </ItemGroup>

In your case,

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp3.1</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Discord.Net" Version="2.2.0" />
    <PackageReference Include="Discord.Net.Core" Version="2.2.0" />
    <PackageReference Include="SkiaSharp" Version="2.80.2" />
    <PackageReference Include="SkiaSharp.NativeAssets.Linux.NoDependencies" Version="2.80.2" />
    <PackageReference Include="SkiaSharp.QrCode" Version="0.4.1" />
  </ItemGroup>

</Project>

@Alex-451
Copy link
Author

Alex-451 commented Nov 25, 2020

I still get the same error using the following package references:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp3.1</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Discord.Net" Version="2.2.0" />
    <PackageReference Include="Discord.Net.Core" Version="2.2.0" />
    <PackageReference Include="SkiaSharp" Version="2.80.2" />
    <PackageReference Include="SkiaSharp.NativeAssets.Linux.NoDependencies" Version="2.80.2" />
    <PackageReference Include="SkiaSharp.QrCode" Version="0.4.1" />
  </ItemGroup>

</Project>

@guitarrapc
Copy link
Owner

I can't reproduce issue, can you provide minimum reproduceable sample?

@Alex-451
Copy link
Author

Alex-451 commented Nov 26, 2020

I gave you access to the repo (branch: feature/QRCode_generation_rework).
Note: if you want to test the bot make sure to add a discord bot token as well as a prefix in the config.json file (gets created if you run the program for the first time under Resource/config.json)

i use the following command to publish my solution:

dotnet publish -c Release -r linux-x64 --self-contained false

As soon as it hits this part:

info = new SKImageInfo(660, 660);

it crashes with the same error.

@guitarrapc
Copy link
Owner

thank you, I will check it later.

@Alex-451
Copy link
Author

Alex-451 commented Nov 26, 2020

Awesome thanks, i will also add a short video later on that shows exactly what i mean.
(NVM cant send a video because github doesnt support that)

@Alex-451
Copy link
Author

@guitarrapc did you firgure anything out / did you manage to reproduce the issue?

@guitarrapc
Copy link
Owner

@AlexGipp Sorry I was down for these days, Let me check tonight.

@guitarrapc
Copy link
Owner

guitarrapc commented Dec 1, 2020

@AlexGipp Hi, I've tried your repo with this lib's branch.
It seems no trouble with running on WSL2 Ubuntu 20.04 LTS.

# on bash on Ubuntu 20.04 LTS
$ dotnet publish -c Release -r linux-x64 --self-contained false
$ cd ./bin/Release/netcoreapp3.1/linux-x64
$ dotnet YOUR_APP_NAME.dll

I've pushed test code branch to your origin for your reference.
Also I've added docker support, and docker seems no troble with Qr generation.

Let's cralify detail.

  1. What is your Linux environment?
    • Is it docker, or any? If so It can be reprodusable.
  2. If your env can use apt, yum and similar package management, then apt install libfontconfig1 and replace SkiaSharp.NativeAssets.Linux.NoDependencies to SkiaSharp.NativeAssets.Linux package is alternate way.

@Alex-451
Copy link
Author

Alex-451 commented Dec 1, 2020

Thanks for getting back to me @guitarrapc, my linux environment is: Debian 10 x64 (buster)
I will look into the solution you have provided :)

@guitarrapc
Copy link
Owner

guitarrapc commented Dec 1, 2020

A Dockerfile I've pushed to your repo was FROM mcr.microsoft.com/dotnet/core/runtime:3.1-buster-slim AS base, Debian 10 env and it runs successfully.

@Alex-451
Copy link
Author

Alex-451 commented Dec 2, 2020

@guitarrapc So how did you actually solve the issue?
(Note that i have never used docker and have no idea how it works)

@guitarrapc
Copy link
Owner

@AlexGipp I did nothing to docker image, it means default 3.1-buster-slim image doens't trouble any.

image seems setup with https://github.com/dotnet/dotnet-docker/blob/801573a24f0c45fabb0db24ff8d3425c1957e068/src/runtime/3.1/buster-slim/amd64/Dockerfile and https://github.com/dotnet/dotnet-docker/blob/c0e8be8a44b47b1dcc2a5b4b2ebd92022087ac0b/src/runtime-deps/3.1/buster-slim/amd64/Dockerfile based on buster's scratch image https://github.com/debuerreotype/docker-debian-artifacts/blob/794e462d2825fb1ebb3d54ff5c93dd401cf28b9a/buster/slim/Dockerfile.

runtime:3.1-buster-slim has installed packages for dotnet runtime, but it should be same to your env, right?.

        ca-certificates \
        \
        # .NET Core dependencies
        libc6 \
        libgcc1 \
        libgssapi-krb5-2 \
        libicu63 \
        libssl1.1 \
        libstdc++6 \
        zlib1g \

Situation indicate trouble is something due to your environment specific and I need reproduceable step to determine root cause.

@guitarrapc
Copy link
Owner

no update? let's close issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants