Reputation: 844
Full traceback
$ dotnet run avgui.cs
Unhandled exception. System.TypeInitializationException: The type initializer for 'SkiaSharp.SKImageInfo' threw an exception.
---> 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
at SkiaSharp.SkiaApi.sk_colortype_get_default_8888()
at SkiaSharp.SKImageInfo..cctor()
--- End of inner exception stack trace ---
at Avalonia.Skia.PlatformRenderInterface..ctor(ISkiaGpu skiaGpu, Nullable`1 maxResourceBytes) in /_/src/Skia/Avalonia.Skia/PlatformRenderInterface.cs:line 27
at Avalonia.Skia.SkiaPlatform.Initialize(SkiaOptions options) in /_/src/Skia/Avalonia.Skia/SkiaPlatform.cs:line 20
at Avalonia.SkiaApplicationExtensions.<>c__0`1.<UseSkia>b__0_0() in /_/src/Skia/Avalonia.Skia/SkiaApplicationExtensions.cs:line 20
at Avalonia.Controls.AppBuilderBase`1.Setup() in /_/src/Avalonia.Controls/AppBuilderBase.cs:line 304
at Avalonia.Controls.AppBuilderBase`1.SetupWithLifetime(IApplicationLifetime lifetime) in /_/src/Avalonia.Controls/AppBuilderBase.cs:line 179
at Avalonia.ClassicDesktopStyleApplicationLifetimeExtensions.StartWithClassicDesktopLifetime[T](T builder, String[] args, ShutdownMode shutdownMode) in /_/src/Avalonia.Controls/ApplicationLifetimes/ClassicDesktopStyleApplicationLifetime.cs:line 147
at gui_av_c.Program.Main(String[] args) in /home/ibrahim/C#/gui_av_c/Program.cs:line 13
avgui.cs
using Avalonia;
using Avalonia.Controls;
using Avalonia.Interactivity;
using Avalonia.Markup.Xaml;
namespace AvaloniaApplication1
{
public class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
public void button_Click(object sender, RoutedEventArgs e)
{
var button = (Button)sender;
button.Content = "Hello, Avalonia!";
}
private void InitializeComponent()
{
AvaloniaXamlLoader.Load(this);
}
}
}
This is how I setuped the gui_av_c
directory.
~/C#$ mkdir gui_av_c
~/C#$ cd gui_av_c/
~/C#/gui_av_c$ dotnet new avalonia.app
The template "Avalonia .NET Core App" was created successfully.
What I have tried:
$ sudo apt install skia-sharp
$ sudo apt install libskiasharp
$ dotnet add package SkiaSharp.NativeAssets.Linux
Putting libSkiaSharp.so
in \usr\lib
$ lddtree /usr/lib/libSkiaSharp.so
libSkiaSharp.so => /usr/lib/libSkiaSharp.so (interpreter => none)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2
libfontconfig.so.1 => /lib/x86_64-linux-gnu/libfontconfig.so.1
libfreetype.so.6 => /lib/x86_64-linux-gnu/libfreetype.so.6
libpng16.so.16 => /lib/x86_64-linux-gnu/libpng16.so.16
libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1
libexpat.so.1 => /lib/x86_64-linux-gnu/libexpat.so.1
libuuid.so.1 => /lib/x86_64-linux-gnu/libuuid.so.1
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6
ld-linux-x86-64.so.2 => /lib/x86_64-linux-gnu/ld-linux-x86-64.so.2
I am on Ubuntu 20.04.2
Upvotes: 4
Views: 11755
Reputation: 51
You can try install SkiaSharp.NativeAssets.Linux.NoDependencies
NuGet package instead of SkiaSharp
. This solved our problem with "... Unable to load shared library 'libSkiaSharp' or one of its dependencies."
Also if you run the app in a docker container and you want to keep SkiaSharp
Nuget package you will need to install font config:
RUN apt-get update \
&& apt-get install -y --no-install-recommends libfontconfig1 \
&& rm -rf /var/lib/apt/lists/*
Upvotes: 1
Reputation: 3623
You are using .NET SDK from snap. When you run your app with such SDK, snap will start your program in a sandbox environment (that nobody has asked for, especially for an SDK tool, but it does that anyway) with its own root file system without native dependencies required by Avalonia. Nothing you install on the main system will affect said sandbox. It just won't work.
Purge snap-installed .NET SDK from your system (preferably alongside with snap itself) and install using instructions from https://learn.microsoft.com/en-us/dotnet/core/install/linux-ubuntu#2004- :
wget https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
rm packages-microsoft-prod.deb
sudo apt-get update; \
sudo apt-get install -y apt-transport-https && \
sudo apt-get update && \
sudo apt-get install -y dotnet-sdk-5.0
Upvotes: 5