From affebf0655f6f436edfc5c931259ea43cdce8db3 Mon Sep 17 00:00:00 2001 From: Hendrik Mennen Date: Thu, 9 Apr 2026 17:29:05 +0200 Subject: [PATCH 1/2] . --- src/OneWare.Core/Services/PluginService.cs | 13 ++----------- src/OneWare.Essentials/Helpers/PlatformHelper.cs | 6 +++--- 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/src/OneWare.Core/Services/PluginService.cs b/src/OneWare.Core/Services/PluginService.cs index ba1506046..4909a8eb7 100644 --- a/src/OneWare.Core/Services/PluginService.cs +++ b/src/OneWare.Core/Services/PluginService.cs @@ -201,15 +201,6 @@ private void SetupNativeImports(string pluginPath) var libFileName = PlatformHelper.GetLibraryFileName(libraryName); var libPath = Path.Combine(pluginPath, libFileName); - // Remove the 'lib' prefix and '.so' suffix, since some libraries are named like that for compatibility reasons - if (libFileName.EndsWith(".so.dll") && RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) - { - libFileName = libFileName.Replace(".so.dll", ".dll"); - - if (libFileName.StartsWith("lib")) - libFileName = libFileName[3..]; - } - // Try 2 : look in runtimes folder if (!File.Exists(libPath)) libPath = Path.Combine(pluginPath, "runtimes", PlatformHelper.PlatformIdentifier, "native", @@ -231,12 +222,12 @@ private void SetupNativeImports(string pluginPath) // Try 6: Same as 5 but added lib Prefix if (!File.Exists(libPath)) libPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, $"lib{libFileName}"); - + if (NativeLibrary.TryLoad(libPath, out var customHandle)) return customHandle; if (NativeLibrary.TryLoad(libraryName, out var handle)) return handle; - Console.WriteLine($"Loading native library {libraryName} failed"); + Console.WriteLine($"Loading native library {libraryName} failed {File.Exists(libPath)}"); return IntPtr.Zero; }); diff --git a/src/OneWare.Essentials/Helpers/PlatformHelper.cs b/src/OneWare.Essentials/Helpers/PlatformHelper.cs index cca7250de..ec380ffc9 100644 --- a/src/OneWare.Essentials/Helpers/PlatformHelper.cs +++ b/src/OneWare.Essentials/Helpers/PlatformHelper.cs @@ -80,11 +80,11 @@ static PlatformHelper() public static string GetLibraryFileName(string libraryName) { if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) - return $"{libraryName}.dll"; // Windows uses .dll + return libraryName.EndsWith(".dll", StringComparison.OrdinalIgnoreCase) ? libraryName : $"{libraryName}.dll"; if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) - return $"{libraryName}.dylib"; // macOS uses .dylib + return libraryName.EndsWith(".dylib", StringComparison.OrdinalIgnoreCase) ? libraryName : $"{libraryName}.dylib"; if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) - return $"{libraryName}.so"; // Linux uses .so + return libraryName.EndsWith(".so", StringComparison.OrdinalIgnoreCase) ? libraryName : $"{libraryName}.so"; throw new PlatformNotSupportedException("Unsupported operating system."); } From cf720e72ac623af37a59554af58b57e2cb3ec2bb Mon Sep 17 00:00:00 2001 From: Hendrik Mennen Date: Thu, 9 Apr 2026 17:56:04 +0200 Subject: [PATCH 2/2] swap ord --- src/OneWare.Core/Services/PluginService.cs | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/OneWare.Core/Services/PluginService.cs b/src/OneWare.Core/Services/PluginService.cs index 4909a8eb7..afc363b6a 100644 --- a/src/OneWare.Core/Services/PluginService.cs +++ b/src/OneWare.Core/Services/PluginService.cs @@ -197,22 +197,23 @@ private void SetupNativeImports(string pluginPath) { NativeLibrary.SetDllImportResolver(assembly, (libraryName, _, _) => { - // Try 1 + // Try 1 : Check runtimes folder var libFileName = PlatformHelper.GetLibraryFileName(libraryName); - var libPath = Path.Combine(pluginPath, libFileName); + var libPath = Path.Combine(pluginPath, "runtimes", PlatformHelper.PlatformIdentifier, "native", + libFileName); - // Try 2 : look in runtimes folder + // Try 2 : add lib infront in runtimes folder if (!File.Exists(libPath)) libPath = Path.Combine(pluginPath, "runtimes", PlatformHelper.PlatformIdentifier, "native", - libFileName); + $"lib{libFileName}"); - // Try 3: add lib infront of it - if (!File.Exists(libPath)) libPath = Path.Combine(pluginPath, $"lib{libFileName}"); + // Try 3: check base + if (!File.Exists(libPath)) + libPath = Path.Combine(pluginPath, libFileName); - // Try 4 : look in (plugin) runtimes folder with lib infront + // Try 4 : base with lib infront if (!File.Exists(libPath)) - libPath = Path.Combine(pluginPath, "runtimes", PlatformHelper.PlatformIdentifier, "native", - $"lib{libFileName}"); + libPath = Path.Combine(pluginPath, $"lib{libFileName}"); // Try 5: MacOS weirdness, look in (own) base folder // TODO find out why this is not automatic in MacOS, and why even without this we don't have issues