diff --git a/src/Jackett.Common/Indexers/BaseIndexer.cs b/src/Jackett.Common/Indexers/BaseIndexer.cs index 09bd47ac2..2dd2f66da 100644 --- a/src/Jackett.Common/Indexers/BaseIndexer.cs +++ b/src/Jackett.Common/Indexers/BaseIndexer.cs @@ -10,7 +10,6 @@ using NLog; using System; using System.Collections.Generic; using System.Linq; -using System.Runtime.InteropServices; using System.Text; using System.Threading.Tasks; using static Jackett.Common.Models.IndexerConfig.ConfigurationData; @@ -177,10 +176,9 @@ namespace Jackett.Common.Indexers //TODO: Remove this section once users have moved off DPAPI private bool MigratedFromDPAPI(JToken jsonConfig) { - bool runningOnDotNetCore = RuntimeInformation.FrameworkDescription.IndexOf("core", StringComparison.OrdinalIgnoreCase) >= 0; bool isWindows = Environment.OSVersion.Platform == PlatformID.Win32NT; - if (!isWindows && runningOnDotNetCore) + if (!isWindows && DotNetCoreUtil.IsRunningOnDotNetCore) { // User isn't running Windows, but is running on .NET Core framework, no access to the DPAPI, so don't bother trying to migrate return false; diff --git a/src/Jackett.Common/Utils/DotNetCoreUtil.cs b/src/Jackett.Common/Utils/DotNetCoreUtil.cs new file mode 100644 index 000000000..529528d92 --- /dev/null +++ b/src/Jackett.Common/Utils/DotNetCoreUtil.cs @@ -0,0 +1,28 @@ +using System; +using System.Runtime.InteropServices; + +namespace Jackett.Common.Utils +{ + public static class DotNetCoreUtil + { + public static bool IsRunningOnDotNetCore + { + get + { + bool runningOnDotNetCore = false; + + try + { + runningOnDotNetCore = RuntimeInformation.FrameworkDescription.IndexOf("core", StringComparison.OrdinalIgnoreCase) >= 0; + } + catch + { + //Issue only appears to occur for small number of users on Mono + runningOnDotNetCore = false; + } + + return runningOnDotNetCore; + } + } + } +} diff --git a/src/Jackett.Server/Initialisation.cs b/src/Jackett.Server/Initialisation.cs index 34b1942dd..4b5d22ff6 100644 --- a/src/Jackett.Server/Initialisation.cs +++ b/src/Jackett.Server/Initialisation.cs @@ -4,8 +4,6 @@ using Jackett.Common.Utils; using Jackett.Server.Services; using NLog; using System; -using System.Linq; -using System.Runtime.InteropServices; namespace Jackett.Server { @@ -113,8 +111,8 @@ namespace Jackett.Server { logger.Info("Overriding port to " + consoleOptions.Port); serverConfig.Port = consoleOptions.Port; - bool isWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows); - if (isWindows) + + if (EnvironmentUtil.IsWindows) { if (ServerUtil.IsUserAdministrator()) { @@ -137,7 +135,7 @@ namespace Jackett.Server { logger.Info("Overriding external access to " + consoleOptions.ListenPublic); serverConfig.AllowExternal = consoleOptions.ListenPublic; - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (EnvironmentUtil.IsWindows) { if (ServerUtil.IsUserAdministrator()) { diff --git a/src/Jackett.Server/Program.cs b/src/Jackett.Server/Program.cs index 543c584e8..e4c180409 100644 --- a/src/Jackett.Server/Program.cs +++ b/src/Jackett.Server/Program.cs @@ -47,9 +47,7 @@ namespace Jackett.Server { if (string.IsNullOrEmpty(options.Client)) { - bool runningOnDotNetCore = RuntimeInformation.FrameworkDescription.IndexOf("Core", StringComparison.OrdinalIgnoreCase) >= 0; - - if (runningOnDotNetCore) + if (DotNetCoreUtil.IsRunningOnDotNetCore) { options.Client = "httpclientnetcore"; } diff --git a/src/Jackett.Server/Services/ServerService.cs b/src/Jackett.Server/Services/ServerService.cs index 96f2f7872..daf1497d6 100644 --- a/src/Jackett.Server/Services/ServerService.cs +++ b/src/Jackett.Server/Services/ServerService.cs @@ -1,5 +1,6 @@ using Jackett.Common.Models.Config; using Jackett.Common.Services.Interfaces; +using Jackett.Common.Utils; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.WebUtilities; using NLog; @@ -121,10 +122,8 @@ namespace Jackett.Server.Services logger.Error(e, "Error while reading the issue file"); } - bool runningOnDotNetCore = RuntimeInformation.FrameworkDescription.IndexOf("Core", StringComparison.OrdinalIgnoreCase) >= 0; - Type monotype = Type.GetType("Mono.Runtime"); - if (monotype != null && !runningOnDotNetCore) + if (monotype != null && !DotNetCoreUtil.IsRunningOnDotNetCore) { MethodInfo displayName = monotype.GetMethod("GetDisplayName", BindingFlags.NonPublic | BindingFlags.Static); var monoVersion = "unknown";