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!
The tests run successfully - the .so file is found and loaded by the method under test.
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
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
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
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
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