Sdk: "dotnet test" fails to find .so file in output folder on Ubuntu when LD_LIBRARY_PATH is blank.

Created on 11 Jul 2018  路  3Comments  路  Source: dotnet/sdk

I have a cross-platform project which uses [DllImport] to load a native binary. I have equivalent .dll and .so placed in the application root, set to CopyAlways and they appear in the output folder.

The application runs correctly on both Windows and Linux (Ubuntu) both when published and from the command line with "dotnet run".

I have a test which calls a method from the loaded library. On Windows the test runs correctly, on a Linux system when LD_LIBRARY_PATH is not set (such as the visualstudio.com hosted Linux build agent) the test fails with a DllNotFoundException.

Setting the LD_LIBRARY_PATH to : (just a colon) causes the tests to pass. I believe an incorrect assumption is made somewhere during the test procedure about LD_LIBRARY_PATH.

Further details below, including further tests.

Many thanks!

Steps to reproduce

  1. Create a project with a [DllImport] method from a library.so file.
  2. Create a test for the method.
  3. Set the library.so file to CopyAlways so it appears in the output folder alongside the normal application dlls.
  4. Use the VSTS hosted linux build agent or host your own linux vsts-agent which has no LD_LIBRARY_PATH by default.
  5. Build the project and run it - the method successfully loads the library.so file from the application folder and runs the imported method properly.
  6. Run "dotnet test" against the project and you get DllNotFoundException.

Expected behavior

The tests run successfully - the .so file is found and loaded by the method under test.

Actual behavior

Error Message:
System.DllNotFoundException : Unable to load shared library 'library.so' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: liblibrary: cannot open shared object file: No such file or directory

Additional info

The fact that LD_LIBRARY_PATH is blank is relevant.
If LD_LIBRARY_PATH either starts or ends with a : then the test runs correctly.

export LD_LIBRARY_PATH=
dotnet test
fails with error above

export LD_LIBRARY_PATH=:
dotnet test
passes

export LD_LIBRARY_PATH=:blah
dotnet test
passes

export LD_LIBRARY_PATH=blah:
dotnet test
passes

export LD_LIBRARY_PATH=blah
dotnet test
fails with error above

export LD_LIBRARY_PATH=path_to_application_output_directory
dotnet test
passes

Environment data

dotnet --info output:

root@vsts-agent-5c87858b7b-dsbjf:/vsts# dotnet --info
.NET Core SDK (reflecting any global.json):
Version: 2.1.301
Commit: 59524873d6

Runtime Environment:
OS Name: ubuntu
OS Version: 16.04
OS Platform: Linux
RID: ubuntu.16.04-x64
Base Path: /usr/share/dotnet/sdk/2.1.301/

Host (useful for support):
Version: 2.1.1
Commit: 6985b9f684

.NET Core SDKs installed:
2.1.301 [/usr/share/dotnet/sdk]

.NET Core runtimes installed:
Microsoft.AspNetCore.All 2.1.1 [/usr/share/dotnet/shared/Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.1 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.1.1 [/usr/share/dotnet/shared/Microsoft.NETCore.App]

To install additional .NET Core runtimes or SDKs:
https://aka.ms/dotnet-download

Most helpful comment

The guys at vstest have closed the issue and suggested I report it here!

https://github.com/Microsoft/vstest/issues/1690#issuecomment-441165838

All 3 comments

This issue was moved to Microsoft/vstest#1690

The guys at vstest have closed the issue and suggested I report it here!

https://github.com/Microsoft/vstest/issues/1690#issuecomment-441165838

Was this page helpful?
0 / 5 - 0 ratings