Solving libX11 not found on F# .Net Core project

Steps to reproduce:

  • Install the latest .Net sdk on NixOS
  • dotnet new -i JaggerJo.Avalonia.FuncUI.Templates
  • dotnet new avalonia-funcUI-basic -n NewApp
  • cd NewApp

then:

$ # runs fine
$ dotnet build
$ # breaks
$ dotnet run
Unhandled Exception: System.DllNotFoundException: Unable to load shared library 'libX11.so.6' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: liblibX11.so.6.so: cannot open shared object file: No such file or directory
   at Avalonia.X11.XLib.XInitThreads()
   at Avalonia.X11.AvaloniaX11Platform.Initialize(X11PlatformOptions options) in D:\a\1\s\src\Avalonia.X11\X11Platform.cs:line 31
   at Avalonia.Controls.AppBuilderBase`1.Setup() in D:\a\1\s\src\Avalonia.Controls\AppBuilderBase.cs:line 302
   at Avalonia.Controls.AppBuilderBase`1.Start(AppMainDelegate main, String[] args) in D:\a\1\s\src\Avalonia.Controls\AppBuilderBase.cs:line 153
   at App.Program.Main(String[] args) in /home/usul/Github/Horatius/src/App/Main.fs:line 56

Also, this seems to be posted as an issue on nixpkgs on dotnet cannot find libX11.so.6.

This is the current shell.nix I’m using for now (dotnet-sdk is installed globally):

{ pkgs ? import ./pinned-nixpkgs.nix {} }:

pkgs.multiStdenv.mkDerivation {
  name = "dev-shell";

  buildInputs = with pkgs; [
    libgdiplus
    mono6
    xorg.libX11
  ];
}

Any way to do a shellHook so libX11 gets workings correctly? Or is this an issue with a missing 32-bit lib?

I’ve managed to solve this by setting LD_LIBRARY_PATH correctly in a shell.nix. My solution is posted in this issue if someone ever has a similar problem like this again.

~]$ dotnet build ; dotnet run
Microsoft ® Build Engine version 16.4.0+e901037fe for .NET Core
Copyright © Microsoft Corporation. All rights reserved.

Restore completed in 25.9 ms for /home/user/Proj.csproj.
Proj -> /home/user/Proj/bin/Debug/netcoreapp3.1/Proj.dll

Build succeeded.
0 Warning(s)
0 Error(s)

Time Elapsed 00:00:00.86
Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object.
at Avalonia.Shared.PlatformSupport.StandardRuntimePlatform.UnmanagedBlob.DoDispose()
at Avalonia.Shared.PlatformSupport.StandardRuntimePlatform.UnmanagedBlob.Finalize()

1 Like

It seems the issue was with the Avalonia lib and it’s already fixed

1 Like