diff --git a/Whisper.net/LibraryLoader/NativeLibraryLoader.cs b/Whisper.net/LibraryLoader/NativeLibraryLoader.cs index c1c4c925..118b7d3a 100644 --- a/Whisper.net/LibraryLoader/NativeLibraryLoader.cs +++ b/Whisper.net/LibraryLoader/NativeLibraryLoader.cs @@ -185,13 +185,16 @@ private static bool IsRuntimeSupported(RuntimeLibrary runtime, string platform, _ => throw new PlatformNotSupportedException($"Unsupported OS platform, architecture: {RuntimeInformation.OSArchitecture}") }; + var assemblyLocation = typeof(NativeLibraryLoader).Assembly.Location; + var environmentAppStartLocation = Environment.GetCommandLineArgs()[0]; + // NetFramework and Mono will crash if we try to get the directory of an empty string. var assemblySearchPaths = new[] { AppDomain.CurrentDomain.RelativeSearchPath, AppDomain.CurrentDomain.BaseDirectory, - Path.GetDirectoryName(typeof(NativeLibraryLoader).Assembly.Location), - Path.GetDirectoryName(Environment.GetCommandLineArgs()[0]) - }.Where(it => !string.IsNullOrEmpty(it)); + string.IsNullOrWhiteSpace(assemblyLocation) ? null : Path.GetDirectoryName(assemblyLocation), + string.IsNullOrWhiteSpace(environmentAppStartLocation) ? null : Path.GetDirectoryName(environmentAppStartLocation) + }.Where(it => !string.IsNullOrEmpty(it)).Distinct(); foreach (var library in RuntimeOptions.Instance.RuntimeLibraryOrder) {