From d0a4bc0700ab212feae3d352e6d9b0948bada275 Mon Sep 17 00:00:00 2001 From: Ian Griffiths Date: Fri, 3 Mar 2023 18:59:30 +0000 Subject: [PATCH 1/6] Upgrade to supported TFMs and SDK versions Remove dependency on System.Runtime.InteropServices.WindowsRuntime in netstandard2.0 - this wouldn't work right on net6.0 or later because they use C#/WinRT for interop --- Rx.NET/Source/Directory.build.props | 4 ++ Rx.NET/Source/Directory.build.targets | 14 +---- .../Microsoft.Reactive.Testing.csproj | 2 +- .../System.Reactive.Observable.Aliases.csproj | 2 +- .../Internal/ReflectionUtils.cs | 47 ++++++++++++--- .../Linq/Observable/FromEventPattern.cs | 10 --- .../System.Reactive/System.Reactive.csproj | 57 +++--------------- .../System.Reactive.net5.0-windows.targets | 9 --- .../build/System.Reactive.targets | 12 ---- .../Package.appxmanifest | 4 +- ...ts.System.Reactive.Uwp.DeviceRunner.csproj | 29 ++++++--- ...Reactive.Uwp.DeviceRunner_TemporaryKey.pfx | Bin 2504 -> 2512 bytes .../DispatcherHelpers.cs | 2 +- .../Tests.System.Reactive.csproj | 4 +- azure-pipelines.rx.yml | 33 +++------- 15 files changed, 92 insertions(+), 137 deletions(-) delete mode 100644 Rx.NET/Source/src/System.Reactive/build/System.Reactive.net5.0-windows.targets delete mode 100644 Rx.NET/Source/src/System.Reactive/build/System.Reactive.targets diff --git a/Rx.NET/Source/Directory.build.props b/Rx.NET/Source/Directory.build.props index 364b42e2..2e16b5d1 100644 --- a/Rx.NET/Source/Directory.build.props +++ b/Rx.NET/Source/Directory.build.props @@ -20,6 +20,10 @@ true true latest + + + 5-Default + $(NoWarn);CS8600;CS8602;CS8603;CS8604;CS8632;CA1000;CA1003;CA1014;CA1019;CA1033;CA1045;CA1051;CA1052;CA1063;CA1067;CA1068;CA1507;CA1707;CA1711;CA1716;CA1720;CA1806;CA1815;CA1816;CA1822;CA1825;CA1840;CA1845;CA2016;CA2109;CA2201;CA2211;CA2213;CA2249;IDE0003;IDE0016;IDE0017;IDE0018;IDE0019;IDE0020;IDE0031;IDE0032;IDE0034;IDE0037;IDE0038;IDE0039;IDE0040;IDE0044;IDE0051;IDE0052;IDE0056;IDE0057;IDE0059;IDE0060;IDE0062;IDE0063;IDE0071;IDE0074;IDE0075;IDE0076;IDE0077;IDE0079;IDE0083;IDE0090;IDE0180;IDE0270;IDE0280;IDE1006;IDE1056 diff --git a/Rx.NET/Source/Directory.build.targets b/Rx.NET/Source/Directory.build.targets index 6b2ec3af..4cb6ebee 100644 --- a/Rx.NET/Source/Directory.build.targets +++ b/Rx.NET/Source/Directory.build.targets @@ -9,26 +9,18 @@ $(DefineConstants);HAS_WINFORMS;HAS_WPF;HAS_WINRT;HAS_DISPATCHER;HAS_REMOTING;DESKTOPCLR;NO_NULLABLE_ATTRIBUTES - - 10.0.19041.0 - 10.0.15063.0 - $(DefineConstants);HAS_WINRT;NO_CODE_COVERAGE_ATTRIBUTE;NO_SERIALIZABLE;CRIPPLED_REFLECTION;NO_THREAD;NO_TRACE;WINDOWS;NO_NULLABLE_ATTRIBUTES - $(DefineConstants);HAS_WINRT;WINDOWS;HAS_OS_XAML;LEGACY_WINRT;NO_NULLABLE_ATTRIBUTES 10.0.19041.0 - + $(DefineConstants);HAS_WINRT;NO_NULLABLE_ATTRIBUTES - - $(DefineConstants);HAS_WINRT;HAS_WINFORMS;HAS_WPF;HAS_DISPATCHER;DESKTOPCLR - - + $(DefineConstants);HAS_WINRT;HAS_WINFORMS;HAS_WPF;HAS_DISPATCHER;DESKTOPCLR;WINDOWS;CSWINRT - + diff --git a/Rx.NET/Source/src/Microsoft.Reactive.Testing/Microsoft.Reactive.Testing.csproj b/Rx.NET/Source/src/Microsoft.Reactive.Testing/Microsoft.Reactive.Testing.csproj index dc14fc86..4c22d608 100644 --- a/Rx.NET/Source/src/Microsoft.Reactive.Testing/Microsoft.Reactive.Testing.csproj +++ b/Rx.NET/Source/src/Microsoft.Reactive.Testing/Microsoft.Reactive.Testing.csproj @@ -1,6 +1,6 @@  - netcoreapp3.1;net472;uap10.0.16299;netstandard2.0;net5.0 + netstandard2.0;net472;uap10.0.16299;net6.0 false Reactive Extensions Testing Library containing interfaces and classes providing functionality to test applications and libraries built using Reactive Extensions. Microsoft.Reactive.Testing - Testing Helper Library diff --git a/Rx.NET/Source/src/System.Reactive.Observable.Aliases/System.Reactive.Observable.Aliases.csproj b/Rx.NET/Source/src/System.Reactive.Observable.Aliases/System.Reactive.Observable.Aliases.csproj index 30ac64cf..8a0ff302 100644 --- a/Rx.NET/Source/src/System.Reactive.Observable.Aliases/System.Reactive.Observable.Aliases.csproj +++ b/Rx.NET/Source/src/System.Reactive.Observable.Aliases/System.Reactive.Observable.Aliases.csproj @@ -1,6 +1,6 @@  - netstandard2.0;net472;uap10.0.16299;net5.0 + netstandard2.0;net472;uap10.0.16299;net6.0 Reactive Extensions - Aliases false Rx;Reactive;Extensions;Observable;LINQ;Events diff --git a/Rx.NET/Source/src/System.Reactive/Internal/ReflectionUtils.cs b/Rx.NET/Source/src/System.Reactive/Internal/ReflectionUtils.cs index a98ac7b4..d913ead5 100644 --- a/Rx.NET/Source/src/System.Reactive/Internal/ReflectionUtils.cs +++ b/Rx.NET/Source/src/System.Reactive/Internal/ReflectionUtils.cs @@ -5,10 +5,6 @@ using System.Globalization; using System.Reflection; -#if HAS_WINRT -using System.Runtime.InteropServices.WindowsRuntime; -#endif - namespace System.Reactive { internal static class ReflectionUtils @@ -76,18 +72,16 @@ namespace System.Reactive isWinRT = false; -#if HAS_WINRT && !CSWINRT - if (addMethod.ReturnType == typeof(EventRegistrationToken)) + if (IsWinRTEventRegistrationTokenType(addMethod.ReturnType)) { isWinRT = true; var pet = psr[0]; - if (pet.ParameterType != typeof(EventRegistrationToken)) + if (IsWinRTEventRegistrationTokenType(pet.ParameterType)) { throw new InvalidOperationException(Strings_Linq.EVENT_WINRT_REMOVE_METHOD_SHOULD_TAKE_ERT); } } -#endif delegateType = psa[0].ParameterType; @@ -119,5 +113,42 @@ namespace System.Reactive #if (CRIPPLED_REFLECTION && HAS_WINRT) public static MethodInfo GetMethod(this Type type, string name) => type.GetTypeInfo().GetDeclaredMethod(name); #endif + + /// + /// Determine whether a type represents a WinRT event registration token + /// (https://learn.microsoft.com/en-us/uwp/api/windows.foundation.eventregistrationtoken). + /// + /// The type to check. + /// True if this represents a WinRT event registration token + /// + /// + /// We used to perform a simple comparison with typeof(EventRegistrationToken), but the + /// introduction of C#/WinRT has made this problematic. Before C#/WinRT, the .NET + /// projection of WinRT's Windows.Foundation.EventRegistrationToken type was + /// System.Runtime.InteropServices.WindowsRuntime.EventRegistrationToken. But that type is + /// associated with the old WinRT interop mechanisms in which the CLR works directly with + /// WinMD. That was how it worked up as far as .NET Core 3.1, and it's still how .NET + /// Framework works, but this direct WinMD support was removed in .NET 5.0. + /// + /// + /// If you're on .NET 5.0 or later, the System.Runtime.InteropServices.WindowsRuntime types + /// are no longer supported. While you can still get access to them through the NuGet + /// package of the same name (that's how .NET Standard 2.0 libraries are able to use these + /// types) they are best avoided, because the types in that library are no longer the types + /// you see when any of the WinRT types they are meant to represent are projected into the + /// CLR's world. + /// + /// + /// It was therefore necessary for Rx to stop using these types, and to drop its reference + /// to the System.Runtime.InteropServices.WindowsRuntime package. We can replicate the + /// same logic by looking for the type name. By checking for either the old or new + /// namespaces, we can support both the old projection (still used on .NET Framework) and + /// also the new C#/WinRT projection. + /// + /// + private static bool IsWinRTEventRegistrationTokenType(Type t) => + t.Name == "EventRegistrationToken" && + (t.Namespace == "System.Runtime.InteropServices.WindowsRuntime" || + t.Namespace == "WinRT"); } } diff --git a/Rx.NET/Source/src/System.Reactive/Linq/Observable/FromEventPattern.cs b/Rx.NET/Source/src/System.Reactive/Linq/Observable/FromEventPattern.cs index 16ee7bb9..f5b6110a 100644 --- a/Rx.NET/Source/src/System.Reactive/Linq/Observable/FromEventPattern.cs +++ b/Rx.NET/Source/src/System.Reactive/Linq/Observable/FromEventPattern.cs @@ -69,18 +69,12 @@ namespace System.Reactive.Linq.ObservableImpl private readonly MethodInfo _addMethod; private readonly MethodInfo _removeMethod; private readonly Func _getResult; -#if HAS_WINRT private readonly bool _isWinRT; -#endif public Handler(object? target, Type delegateType, MethodInfo addMethod, MethodInfo removeMethod, Func getResult, bool isWinRT, IScheduler scheduler) : base(scheduler) { -#if HAS_WINRT _isWinRT = isWinRT; -#else - System.Diagnostics.Debug.Assert(!isWinRT); -#endif _target = target; _delegateType = delegateType; _addMethod = addMethod; @@ -100,13 +94,11 @@ namespace System.Reactive.Linq.ObservableImpl try { -#if HAS_WINRT if (_isWinRT) { removeHandler = AddHandlerCoreWinRT(handler); } else -#endif { removeHandler = AddHandlerCore(handler); } @@ -147,13 +139,11 @@ namespace System.Reactive.Linq.ObservableImpl return () => _removeMethod.Invoke(_target, new object[] { handler }); } -#if HAS_WINRT private Action AddHandlerCoreWinRT(Delegate handler) { var token = _addMethod.Invoke(_target, new object[] { handler }); return () => _removeMethod.Invoke(_target, new[] { token }); } -#endif } } } diff --git a/Rx.NET/Source/src/System.Reactive/System.Reactive.csproj b/Rx.NET/Source/src/System.Reactive/System.Reactive.csproj index dac82bde..6d98592b 100644 --- a/Rx.NET/Source/src/System.Reactive/System.Reactive.csproj +++ b/Rx.NET/Source/src/System.Reactive/System.Reactive.csproj @@ -1,6 +1,6 @@  - netcoreapp3.1;netstandard2.0;net472;uap10.0.16299;net5.0;net5.0-windows10.0.19041 + netstandard2.0;net472;uap10.0.16299;net6.0;net6.0-windows10.0.19041 false Rx;Reactive;Extensions;Observable;LINQ;Events Reactive Extensions (Rx) for .NET @@ -10,16 +10,11 @@ enable - + true true - false - - - - @@ -36,23 +31,13 @@ - - - - - - - - - - - + - + @@ -64,7 +49,7 @@ - + @@ -159,36 +144,10 @@ - - $(TargetsForTfmSpecificBuildOutput);RemoveNetCoreApp3FromNuGet - $(TargetsForTfmSpecificContentInPackage);AddNetCore3ToNuGet - - - - - - - - - - - - - - - - - - - - - - - - - - + + + True True diff --git a/Rx.NET/Source/src/System.Reactive/build/System.Reactive.net5.0-windows.targets b/Rx.NET/Source/src/System.Reactive/build/System.Reactive.net5.0-windows.targets deleted file mode 100644 index b3e5a9dc..00000000 --- a/Rx.NET/Source/src/System.Reactive/build/System.Reactive.net5.0-windows.targets +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - diff --git a/Rx.NET/Source/src/System.Reactive/build/System.Reactive.targets b/Rx.NET/Source/src/System.Reactive/build/System.Reactive.targets deleted file mode 100644 index 2452a8e5..00000000 --- a/Rx.NET/Source/src/System.Reactive/build/System.Reactive.targets +++ /dev/null @@ -1,12 +0,0 @@ - - - true - false - - - - - - - - diff --git a/Rx.NET/Source/tests/Tests.System.Reactive.Uwp.DeviceRunner/Package.appxmanifest b/Rx.NET/Source/tests/Tests.System.Reactive.Uwp.DeviceRunner/Package.appxmanifest index 98821d77..feaffe20 100644 --- a/Rx.NET/Source/tests/Tests.System.Reactive.Uwp.DeviceRunner/Package.appxmanifest +++ b/Rx.NET/Source/tests/Tests.System.Reactive.Uwp.DeviceRunner/Package.appxmanifest @@ -8,14 +8,14 @@ Tests.System.Reactive.Uwp.DeviceRunner - oren + ian Assets\StoreLogo.png diff --git a/Rx.NET/Source/tests/Tests.System.Reactive.Uwp.DeviceRunner/Tests.System.Reactive.Uwp.DeviceRunner.csproj b/Rx.NET/Source/tests/Tests.System.Reactive.Uwp.DeviceRunner/Tests.System.Reactive.Uwp.DeviceRunner.csproj index cdddd895..958a2f07 100644 --- a/Rx.NET/Source/tests/Tests.System.Reactive.Uwp.DeviceRunner/Tests.System.Reactive.Uwp.DeviceRunner.csproj +++ b/Rx.NET/Source/tests/Tests.System.Reactive.Uwp.DeviceRunner/Tests.System.Reactive.Uwp.DeviceRunner.csproj @@ -1,5 +1,5 @@  - + Debug @@ -11,19 +11,21 @@ Tests.System.Reactive.Uwp.DeviceRunner en-US UAP - 10.0.17134.0 - 10.0.16299.0 - 14 + 10.0.18362.0 + 10.0.18362.0 + 17 512 {A5A43C5B-DE2A-4C0C-9213-0A381AF9435A};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + $(VisualStudioVersion) Tests.System.Reactive.Uwp.DeviceRunner_TemporaryKey.pfx - 2BD466C3AB205824BF42514FF6A6F268A0B60966 + 8570A5641EDE61A2AB21E12809E9E0376A041E8C false + True true bin\x86\Debug\ - TRACE;DEBUG;NETFX_CORE;WINDOWS_UWP;CODE_ANALYSIS;NO_EVENTARGS_CONSTRAINT;HAS_EDI;HAS_WINRT;HAS_PROGRESS;PREFER_ASYNC;HAS_AWAIT;HAS_APTCA;HAS_TPL46;NO_REMOTING;NO_SERIALIZABLE;NO_THREAD;CRIPPLED_REFLECTION;WINDOWS;USE_TIMER_SELF_ROOT + TRACE;DEBUG;NETFX_CORE;WINDOWS_UWP;CODE_ANALYSIS;NO_EVENTARGS_CONSTRAINT;HAS_EDI;HAS_WINRT;HAS_PROGRESS;PREFER_ASYNC;HAS_AWAIT;HAS_APTCA;HAS_TPL46;NO_REMOTING;NO_THREAD;WINDOWS;USE_TIMER_SELF_ROOT ;2008;0618 full x86 @@ -33,7 +35,7 @@ bin\x86\Release\ - TRACE;NETFX_CORE;WINDOWS_UWP;CODE_ANALYSIS;NO_EVENTARGS_CONSTRAINT;HAS_EDI;HAS_WINRT;HAS_PROGRESS;PREFER_ASYNC;HAS_AWAIT;HAS_APTCA;HAS_TPL46;NO_REMOTING;NO_SERIALIZABLE;NO_THREAD;CRIPPLED_REFLECTION;WINDOWS;USE_TIMER_SELF_ROOT + TRACE;NETFX_CORE;WINDOWS_UWP;CODE_ANALYSIS;NO_EVENTARGS_CONSTRAINT;HAS_EDI;HAS_WINRT;HAS_PROGRESS;PREFER_ASYNC;HAS_AWAIT;HAS_APTCA;HAS_TPL46;NO_REMOTING;NO_THREAD;WINDOWS;USE_TIMER_SELF_ROOT true ;2008;0618 pdbonly @@ -89,6 +91,9 @@ true true + + $(NoWarn);IDE0003;IDE0016;IDE0017;IDE0018;IDE0019;IDE0020;IDE0031;IDE0032;IDE0034;IDE0037;IDE0038;IDE0039;IDE0040;IDE0044;IDE0051;IDE0052;IDE0056;IDE0057;IDE0059;IDE0060;IDE0062;IDE0063;IDE0071;IDE0074;IDE0075;IDE0076;IDE0077;IDE0079;IDE0083;IDE0090;IDE0180;IDE1006;IDE1056 + @@ -160,6 +165,16 @@ ..\..\ReactiveX.snk + + + 7.0.103 +