'SkiaSharp.SKImageInfo' 的类型初始值设定项抛出异常 Avalonia
Type initializer for 'SkiaSharp.SKImageInfo' threw an exception Avalonia
完整追溯
$ 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);
}
}
}
这就是我设置 gui_av_c
目录的方式。
~/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.
我试过的:
$ sudo apt install skia-sharp
$ sudo apt install libskiasharp
$ dotnet add package SkiaSharp.NativeAssets.Linux
将 libSkiaSharp.so
放入 \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
我在 Ubuntu 20.04.2
您正在使用来自 snap 的 .NET SDK。当您 运行 您的应用程序使用此类 SDK 时,snap 将在沙盒环境中启动您的程序(没有人要求,特别是对于 SDK 工具,但无论如何它都会这样做)具有自己的根文件系统,没有本机依赖项阿瓦隆尼亚要求。您在主系统上安装的任何内容都不会影响上述沙箱。就是不行。
从您的系统中清除 snap 安装的 .NET SDK(最好连同 snap 本身)并使用 https://docs.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
完整追溯
$ 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);
}
}
}
这就是我设置 gui_av_c
目录的方式。
~/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.
我试过的:
$ sudo apt install skia-sharp
$ sudo apt install libskiasharp
$ dotnet add package SkiaSharp.NativeAssets.Linux
将 libSkiaSharp.so
放入 \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
我在 Ubuntu 20.04.2
您正在使用来自 snap 的 .NET SDK。当您 运行 您的应用程序使用此类 SDK 时,snap 将在沙盒环境中启动您的程序(没有人要求,特别是对于 SDK 工具,但无论如何它都会这样做)具有自己的根文件系统,没有本机依赖项阿瓦隆尼亚要求。您在主系统上安装的任何内容都不会影响上述沙箱。就是不行。
从您的系统中清除 snap 安装的 .NET SDK(最好连同 snap 本身)并使用 https://docs.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