From 00760836fbbb04e6f97c67159cd060a09bbf44c9 Mon Sep 17 00:00:00 2001 From: Jevon Date: Sun, 1 May 2022 00:20:22 +0100 Subject: [PATCH] Switch to preprocessor directives to avoid need for System.Runtime.InteropServices.RuntimeInformation package on net462 --- .../Core.Tests/Logging/DiagnosticsLoggerTestCase.cs | 7 ++++++- src/Castle.Core/Castle.Core.csproj | 1 - src/Castle.Core/DynamicProxy/ProxyGenerator.cs | 8 +++++++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/Castle.Core.Tests/Core.Tests/Logging/DiagnosticsLoggerTestCase.cs b/src/Castle.Core.Tests/Core.Tests/Logging/DiagnosticsLoggerTestCase.cs index ed4b25b228..029c901be2 100644 --- a/src/Castle.Core.Tests/Core.Tests/Logging/DiagnosticsLoggerTestCase.cs +++ b/src/Castle.Core.Tests/Core.Tests/Logging/DiagnosticsLoggerTestCase.cs @@ -49,7 +49,12 @@ public void Reset() private void AssertAdmin() { - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) +#if NETCOREAPP2_0_OR_GREATER + bool isWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows); +#else + bool isWindows = !RunningOnMono(); +#endif + if (isWindows) { WindowsPrincipal windowsPrincipal = new WindowsPrincipal(WindowsIdentity.GetCurrent()); try diff --git a/src/Castle.Core/Castle.Core.csproj b/src/Castle.Core/Castle.Core.csproj index df0185b27f..679bf7e168 100644 --- a/src/Castle.Core/Castle.Core.csproj +++ b/src/Castle.Core/Castle.Core.csproj @@ -30,7 +30,6 @@ - diff --git a/src/Castle.Core/DynamicProxy/ProxyGenerator.cs b/src/Castle.Core/DynamicProxy/ProxyGenerator.cs index 1e191ec7a2..e51b4b6e8c 100644 --- a/src/Castle.Core/DynamicProxy/ProxyGenerator.cs +++ b/src/Castle.Core/DynamicProxy/ProxyGenerator.cs @@ -556,7 +556,13 @@ public object CreateInterfaceProxyWithTarget(Type interfaceToProxy, object targe if (target != null) { - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && Marshal.IsComObject(target)) +#if NET6_0_OR_GREATER + bool doComHandling = OperatingSystem.IsWindows(); +#else + bool doComHandling = true; +#endif + + if (doComHandling && Marshal.IsComObject(target)) { var interfaceId = interfaceToProxy.GUID; if (interfaceId != Guid.Empty)