Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<PackageProjectUrl>https://www.hdfgroup.org/</PackageProjectUrl>
<Product>HDF.PInvoke</Product>
<RepositoryUrl>https://github.com/HDFGroup/HDF.PInvoke.1.10</RepositoryUrl>
<Version>1.10.612</Version>
<Version>1.10.613</Version>
<Prerelease></Prerelease>

<!-- Derived properties -->
Expand Down
18 changes: 13 additions & 5 deletions src/HDF.PInvoke.1.10/H5DLLImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,13 @@ internal class H5MacDllImporter : H5DLLImporter
// However, to get the lib handle for the symbols, we need to "reopen" it using the correct path.
public H5MacDllImporter(string libName)
{
string filePath;
var fileName = $"lib{libName}.dylib";

var basePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
var localPath = Path.Combine(basePath, fileName);
var packagePath = Path.Combine(basePath, "..", "..", "runtimes", "osx-x64", "native", fileName);

var process = new Process
{
StartInfo = new ProcessStartInfo
Expand All @@ -202,19 +207,22 @@ public H5MacDllImporter(string libName)

process.Start();

var filePath = process.StandardOutput.ReadToEnd()
var resolvedFilePath = process.StandardOutput.ReadToEnd()
.Split('\n')
.Where(line => line.Contains(fileName))
.FirstOrDefault()?
.Split(' ')
.LastOrDefault();

if (filePath == null)
if (resolvedFilePath != null && File.Exists(resolvedFilePath))
filePath = resolvedFilePath;
else if (File.Exists(localPath))
filePath = localPath;
else if (File.Exists(packagePath))
filePath = packagePath;
else
throw new FileNotFoundException(fileName);

if (!File.Exists(filePath))
throw new FileNotFoundException(filePath);

_handle = dlopen(filePath, RTLD_NOW);

if (_handle == IntPtr.Zero)
Expand Down