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

Unhandled Exception: System.DllNotFoundException: Unable to load shared library 'libX11.so.6' #3020

Closed
schonfinkel opened this issue Sep 22, 2019 · 5 comments

Comments

@schonfinkel
Copy link

schonfinkel commented Sep 22, 2019

I'm using NixOS and was trying out the Avalonia.FuncUI, I ran into the following error while using it:

# builds 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 NewApp.Program.Main(String[] args) in /home/usul/Github/Horatius/NewApp/Main.fs:line 56

I've managed to track down this error to this repo via this other issue.

Setting LD_DEBUG to lib I get the following as output:

     28790:     find library=liblibX11.so.6 [0]; searching
     28790:      search path=/nix/store/89di93ibgvdzykyj4g5xmc4f9i5v6k0k-dotnet-sdk-2.2.401/shared/Microsoft.NETCore.App/2.2.6:/nix/store/najvrr9mppdrgjh529l79w8px36wn58z-gcc-8.3.0-lib/lib:/nix/store/j3gfzcvb1r5pf0m1zf7zwagb886wpjd8-libunwind-1.3.1/lib:/nix/store/kszi9vwy4ra7zya9gnqg3rgla81mkcx0-util-linux-2.33.2/lib:/nix/store/vb7zl9wdbmgkkfdkzvklh87lv29mxbds-icu4c-64.2/lib:/nix/store/nrnnvdy72487sv5n83qa04lafbl6nbcl-openssl-1.1.1c/lib:/nix/store/62ar9xmrlcnlgmwgfi77xz6bq1180vhi-zlib-1.2.11/lib:/nix/store/g71bqnq5h65aynf8xr2cv54ybfdhplmv-curl-7.65.3/lib                (RUNPATH from file /nix/store/89di93ibgvdzykyj4g5xmc4f9i5v6k0k-dotnet-sdk-2.2.401/shared/Microsoft.NETCore.App/2.2.6/libcoreclr.so)
     28790:       trying file=/nix/store/89di93ibgvdzykyj4g5xmc4f9i5v6k0k-dotnet-sdk-2.2.401/shared/Microsoft.NETCore.App/2.2.6/liblibX11.so.6
     28790:       trying file=/nix/store/najvrr9mppdrgjh529l79w8px36wn58z-gcc-8.3.0-lib/lib/liblibX11.so.6
     28790:       trying file=/nix/store/j3gfzcvb1r5pf0m1zf7zwagb886wpjd8-libunwind-1.3.1/lib/liblibX11.so.6
     28790:       trying file=/nix/store/kszi9vwy4ra7zya9gnqg3rgla81mkcx0-util-linux-2.33.2/lib/liblibX11.so.6
     28790:       trying file=/nix/store/vb7zl9wdbmgkkfdkzvklh87lv29mxbds-icu4c-64.2/lib/liblibX11.so.6
     28790:       trying file=/nix/store/nrnnvdy72487sv5n83qa04lafbl6nbcl-openssl-1.1.1c/lib/liblibX11.so.6
     28790:       trying file=/nix/store/62ar9xmrlcnlgmwgfi77xz6bq1180vhi-zlib-1.2.11/lib/liblibX11.so.6
     28790:       trying file=/nix/store/g71bqnq5h65aynf8xr2cv54ybfdhplmv-curl-7.65.3/lib/liblibX11.so.6
     28790:      search cache=/nix/store/6yaj6n8l925xxfbcd65gzqx3dz7idrnn-glibc-2.27/etc/ld.so.cache
     28790:      search path=/nix/store/6yaj6n8l925xxfbcd65gzqx3dz7idrnn-glibc-2.27/lib         (system search path)
     28790:       trying file=/nix/store/6yaj6n8l925xxfbcd65gzqx3dz7idrnn-glibc-2.27/lib/liblibX11.so.6
     28790:
     28790:     find library=libX11.so.6.so [0]; searching
     28790:      search path=/nix/store/89di93ibgvdzykyj4g5xmc4f9i5v6k0k-dotnet-sdk-2.2.401/shared/Microsoft.NETCore.App/2.2.6:/nix/store/najvrr9mppdrgjh529l79w8px36wn58z-gcc-8.3.0-lib/lib:/nix/store/j3gfzcvb1r5pf0m1zf7zwagb886wpjd8-libunwind-1.3.1/lib:/nix/store/kszi9vwy4ra7zya9gnqg3rgla81mkcx0-util-linux-2.33.2/lib:/nix/store/vb7zl9wdbmgkkfdkzvklh87lv29mxbds-icu4c-64.2/lib:/nix/store/nrnnvdy72487sv5n83qa04lafbl6nbcl-openssl-1.1.1c/lib:/nix/store/62ar9xmrlcnlgmwgfi77xz6bq1180vhi-zlib-1.2.11/lib:/nix/store/g71bqnq5h65aynf8xr2cv54ybfdhplmv-curl-7.65.3/lib                (RUNPATH from file /nix/store/89di93ibgvdzykyj4g5xmc4f9i5v6k0k-dotnet-sdk-2.2.401/shared/Microsoft.NETCore.App/2.2.6/libcoreclr.so)
     28790:       trying file=/nix/store/89di93ibgvdzykyj4g5xmc4f9i5v6k0k-dotnet-sdk-2.2.401/shared/Microsoft.NETCore.App/2.2.6/libX11.so.6.so
     28790:       trying file=/nix/store/najvrr9mppdrgjh529l79w8px36wn58z-gcc-8.3.0-lib/lib/libX11.so.6.so
     28790:       trying file=/nix/store/j3gfzcvb1r5pf0m1zf7zwagb886wpjd8-libunwind-1.3.1/lib/libX11.so.6.so
     28790:       trying file=/nix/store/kszi9vwy4ra7zya9gnqg3rgla81mkcx0-util-linux-2.33.2/lib/libX11.so.6.so
     28790:       trying file=/nix/store/vb7zl9wdbmgkkfdkzvklh87lv29mxbds-icu4c-64.2/lib/libX11.so.6.so
     28790:       trying file=/nix/store/nrnnvdy72487sv5n83qa04lafbl6nbcl-openssl-1.1.1c/lib/libX11.so.6.so
     28790:       trying file=/nix/store/62ar9xmrlcnlgmwgfi77xz6bq1180vhi-zlib-1.2.11/lib/libX11.so.6.so
     28790:       trying file=/nix/store/g71bqnq5h65aynf8xr2cv54ybfdhplmv-curl-7.65.3/lib/libX11.so.6.so
     28790:      search cache=/nix/store/6yaj6n8l925xxfbcd65gzqx3dz7idrnn-glibc-2.27/etc/ld.so.cache
     28790:      search path=/nix/store/6yaj6n8l925xxfbcd65gzqx3dz7idrnn-glibc-2.27/lib         (system search path)
     28790:       trying file=/nix/store/6yaj6n8l925xxfbcd65gzqx3dz7idrnn-glibc-2.27/lib/libX11.so.6.so
     28790:
     28790:     find library=liblibX11.so.6.so [0]; searching
     28790:      search path=/nix/store/89di93ibgvdzykyj4g5xmc4f9i5v6k0k-dotnet-sdk-2.2.401/shared/Microsoft.NETCore.App/2.2.6:/nix/store/najvrr9mppdrgjh529l79w8px36wn58z-gcc-8.3.0-lib/lib:/nix/store/j3gfzcvb1r5pf0m1zf7zwagb886wpjd8-libunwind-1.3.1/lib:/nix/store/kszi9vwy4ra7zya9gnqg3rgla81mkcx0-util-linux-2.33.2/lib:/nix/store/vb7zl9wdbmgkkfdkzvklh87lv29mxbds-icu4c-64.2/lib:/nix/store/nrnnvdy72487sv5n83qa04lafbl6nbcl-openssl-1.1.1c/lib:/nix/store/62ar9xmrlcnlgmwgfi77xz6bq1180vhi-zlib-1.2.11/lib:/nix/store/g71bqnq5h65aynf8xr2cv54ybfdhplmv-curl-7.65.3/lib                (RUNPATH from file /nix/store/89di93ibgvdzykyj4g5xmc4f9i5v6k0k-dotnet-sdk-2.2.401/shared/Microsoft.NETCore.App/2.2.6/libcoreclr.so)
     28790:       trying file=/nix/store/89di93ibgvdzykyj4g5xmc4f9i5v6k0k-dotnet-sdk-2.2.401/shared/Microsoft.NETCore.App/2.2.6/liblibX11.so.6.so
     28790:       trying file=/nix/store/najvrr9mppdrgjh529l79w8px36wn58z-gcc-8.3.0-lib/lib/liblibX11.so.6.so
     28790:       trying file=/nix/store/j3gfzcvb1r5pf0m1zf7zwagb886wpjd8-libunwind-1.3.1/lib/liblibX11.so.6.so
     28790:       trying file=/nix/store/kszi9vwy4ra7zya9gnqg3rgla81mkcx0-util-linux-2.33.2/lib/liblibX11.so.6.so
     28790:       trying file=/nix/store/vb7zl9wdbmgkkfdkzvklh87lv29mxbds-icu4c-64.2/lib/liblibX11.so.6.so
     28790:       trying file=/nix/store/nrnnvdy72487sv5n83qa04lafbl6nbcl-openssl-1.1.1c/lib/liblibX11.so.6.so
     28790:       trying file=/nix/store/62ar9xmrlcnlgmwgfi77xz6bq1180vhi-zlib-1.2.11/lib/liblibX11.so.6.so
     28790:       trying file=/nix/store/g71bqnq5h65aynf8xr2cv54ybfdhplmv-curl-7.65.3/lib/liblibX11.so.6.so
     28790:      search cache=/nix/store/6yaj6n8l925xxfbcd65gzqx3dz7idrnn-glibc-2.27/etc/ld.so.cache
     28790:      search path=/nix/store/6yaj6n8l925xxfbcd65gzqx3dz7idrnn-glibc-2.27/lib         (system search path)
     28790:       trying file=/nix/store/6yaj6n8l925xxfbcd65gzqx3dz7idrnn-glibc-2.27/lib/liblibX11.so.6.so
     28790:

Unhandled Exception:      28790:        find library=Microsoft.DiaSymReader.Native.amd64.dll [0]; searching
     28790:      search path=/nix/store/89di93ibgvdzykyj4g5xmc4f9i5v6k0k-dotnet-sdk-2.2.401/shared/Microsoft.NETCore.App/2.2.6:/nix/store/najvrr9mppdrgjh529l79w8px36wn58z-gcc-8.3.0-lib/lib:/nix/store/j3gfzcvb1r5pf0m1zf7zwagb886wpjd8-libunwind-1.3.1/lib:/nix/store/kszi9vwy4ra7zya9gnqg3rgla81mkcx0-util-linux-2.33.2/lib:/nix/store/vb7zl9wdbmgkkfdkzvklh87lv29mxbds-icu4c-64.2/lib:/nix/store/nrnnvdy72487sv5n83qa04lafbl6nbcl-openssl-1.1.1c/lib:/nix/store/62ar9xmrlcnlgmwgfi77xz6bq1180vhi-zlib-1.2.11/lib:/nix/store/g71bqnq5h65aynf8xr2cv54ybfdhplmv-curl-7.65.3/lib                (RUNPATH from file /nix/store/89di93ibgvdzykyj4g5xmc4f9i5v6k0k-dotnet-sdk-2.2.401/shared/Microsoft.NETCore.App/2.2.6/libcoreclr.so)
     28790:       trying file=/nix/store/89di93ibgvdzykyj4g5xmc4f9i5v6k0k-dotnet-sdk-2.2.401/shared/Microsoft.NETCore.App/2.2.6/Microsoft.DiaSymReader.Native.amd64.dll

Any hints on how to solve it?

@danwalmsley
Copy link
Member

does your distro have XServer, and does it have X11 in the $PATH?

@kekekeks
Copy link
Member

Most likely caused by NixOS completely ignoring LSB.

You can try messing around with LD_LIBRARY_PATH.

@schonfinkel
Copy link
Author

schonfinkel commented Sep 22, 2019

You can try messing around with LD_LIBRARY_PATH.

Thanks for all who posted here. I managed to solve this issue, since I develop in a sandboxed environment it happened that LD_LIBRARY_PATH was not set correctly.

If any Nix posters come here again, this is the shell.nix I'm using now (might have a couple of unnecessary libs on buildInputs, but it works).

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

pkgs.stdenv.mkDerivation rec {
  name = "dev-shell";

  buildInputs = with pkgs; [
    fontconfig
    mono6
    xorg.libX11
    xorg.libX11.dev
    zlib
  ];

  LD_LIBRARY_PATH = "${lib.makeLibraryPath buildInputs}";
}

@PlumpMath
Copy link

~]$ dotnet build ; dotnet run
Microsoft (R) Build Engine version 16.4.0+e901037fe for .NET Core
Copyright (C) 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()

@schonfinkel
Copy link
Author

For anyone looking for a flake to use while developing with this lib, this is what's working for me:

{
  description = ".NET project template";

  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
    utils.url = "github:numtide/flake-utils";
  };

  outputs = inputs@{ nixpkgs, ... }:
    inputs.utils.lib.eachDefaultSystem (system:
      let
        pkgs = import nixpkgs { inherit system; };
        xorgLibs = with pkgs.xorg; [
          libICE
          libSM
          libX11
          libX11.dev
        ];
      in
      rec {
        # `nix develop`
        devShells.default = with pkgs; mkShell {
          buildInputs = [
            dotnet-sdk_8
            fontconfig
            gnumake
            icu
            openssl
          ] ++ xorgLibs;

          shellHook = ''
            export DOTNET_ROOT=${dotnet-sdk}
            export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${lib.makeLibraryPath ([ fontconfig icu openssl ] ++ xorgLibs) }
          '';
        };
      });
}

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

No branches or pull requests

4 participants