diff --git a/eng/targets/CSharp.Common.targets b/eng/targets/CSharp.Common.targets index 2d9deb5890..c9ef556f4d 100644 --- a/eng/targets/CSharp.Common.targets +++ b/eng/targets/CSharp.Common.targets @@ -13,6 +13,9 @@ $(NoWarn);RS0041 + + + $(NoWarn);CA1416 (TaskContinuationOptions.RunContinuationsAsynchronously); + Completion = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); Completion.Task.ContinueWith( (task, state) => { diff --git a/src/Components/test/E2ETest/ServerExecutionTests/CircuitGracefulTerminationTests.cs b/src/Components/test/E2ETest/ServerExecutionTests/CircuitGracefulTerminationTests.cs index 69c20cb970..eb3340427e 100644 --- a/src/Components/test/E2ETest/ServerExecutionTests/CircuitGracefulTerminationTests.cs +++ b/src/Components/test/E2ETest/ServerExecutionTests/CircuitGracefulTerminationTests.cs @@ -47,7 +47,7 @@ namespace Microsoft.AspNetCore.Components.E2ETest.ServerExecutionTests Browser.MountTestComponent(); Browser.Equal("Current count: 0", () => Browser.FindElement(By.TagName("p")).Text); - GracefulDisconnectCompletionSource = new TaskCompletionSource(TaskContinuationOptions.RunContinuationsAsynchronously); + GracefulDisconnectCompletionSource = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); Sink = _serverFixture.Host.Services.GetRequiredService(); Messages = new List<(Extensions.Logging.LogLevel level, string eventIdName)>(); Sink.MessageLogged += Log; diff --git a/src/DataProtection/DataProtection/src/DataProtectionBuilderExtensions.cs b/src/DataProtection/DataProtection/src/DataProtectionBuilderExtensions.cs index 7789ca074f..e6618bd535 100644 --- a/src/DataProtection/DataProtection/src/DataProtectionBuilderExtensions.cs +++ b/src/DataProtection/DataProtection/src/DataProtectionBuilderExtensions.cs @@ -4,6 +4,7 @@ using System; using System.ComponentModel; using System.IO; +using System.Runtime.Versioning; using System.Security.Cryptography.X509Certificates; using Microsoft.AspNetCore.Cryptography; using Microsoft.AspNetCore.DataProtection.AuthenticatedEncryption; @@ -223,6 +224,7 @@ namespace Microsoft.AspNetCore.DataProtection /// The . /// The location in the registry where keys should be stored. /// A reference to the after this operation has completed. + [SupportedOSPlatform("windows")] public static IDataProtectionBuilder PersistKeysToRegistry(this IDataProtectionBuilder builder, RegistryKey registryKey) { if (builder == null) @@ -356,6 +358,7 @@ namespace Microsoft.AspNetCore.DataProtection /// /// This API is only supported on Windows platforms. /// + [SupportedOSPlatform("windows")] public static IDataProtectionBuilder ProtectKeysWithDpapi(this IDataProtectionBuilder builder) { if (builder == null) @@ -378,6 +381,7 @@ namespace Microsoft.AspNetCore.DataProtection /// /// This API is only supported on Windows platforms. /// + [SupportedOSPlatform("windows")] public static IDataProtectionBuilder ProtectKeysWithDpapi(this IDataProtectionBuilder builder, bool protectToLocalMachine) { if (builder == null) @@ -408,6 +412,7 @@ namespace Microsoft.AspNetCore.DataProtection /// See https://msdn.microsoft.com/en-us/library/windows/desktop/hh706794(v=vs.85).aspx /// for more information on DPAPI-NG. This API is only supported on Windows 8 / Windows Server 2012 and higher. /// + [SupportedOSPlatform("windows")] public static IDataProtectionBuilder ProtectKeysWithDpapiNG(this IDataProtectionBuilder builder) { if (builder == null) @@ -435,6 +440,7 @@ namespace Microsoft.AspNetCore.DataProtection /// and arguments. /// This API is only supported on Windows 8 / Windows Server 2012 and higher. /// + [SupportedOSPlatform("windows")] public static IDataProtectionBuilder ProtectKeysWithDpapiNG(this IDataProtectionBuilder builder, string protectionDescriptorRule, DpapiNGProtectionDescriptorFlags flags) { if (builder == null) diff --git a/src/DataProtection/DataProtection/src/KeyManagement/XmlKeyManager.cs b/src/DataProtection/DataProtection/src/KeyManagement/XmlKeyManager.cs index 736005ecf7..094832e43c 100644 --- a/src/DataProtection/DataProtection/src/KeyManagement/XmlKeyManager.cs +++ b/src/DataProtection/DataProtection/src/KeyManagement/XmlKeyManager.cs @@ -7,6 +7,7 @@ using System.Diagnostics; using System.Globalization; using System.Linq; using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; using System.Threading; using System.Xml; using System.Xml.Linq; @@ -500,6 +501,8 @@ namespace Microsoft.AspNetCore.DataProtection.KeyManagement { if (OSVersionUtil.IsWindows()) { + Debug.Assert(RuntimeInformation.IsOSPlatform(OSPlatform.Windows)); // Hint for the platform compatibility analyzer. + // If the user profile is available, we can protect using DPAPI. // Probe to see if protecting to local user is available, and use it as the default if so. encryptor = new DpapiXmlEncryptor( @@ -523,10 +526,14 @@ namespace Microsoft.AspNetCore.DataProtection.KeyManagement RegistryKey regKeyStorageKey = null; if (OSVersionUtil.IsWindows()) { + Debug.Assert(RuntimeInformation.IsOSPlatform(OSPlatform.Windows)); // Hint for the platform compatibility analyzer. regKeyStorageKey = RegistryXmlRepository.DefaultRegistryKey; } if (regKeyStorageKey != null) { + Debug.Assert(RuntimeInformation.IsOSPlatform(OSPlatform.Windows)); // Hint for the platform compatibility analyzer. + regKeyStorageKey = RegistryXmlRepository.DefaultRegistryKey; + // If the user profile isn't available, we can protect using DPAPI (to machine). encryptor = new DpapiXmlEncryptor(protectToLocalMachine: true, loggerFactory: _loggerFactory); repository = new RegistryXmlRepository(regKeyStorageKey, _loggerFactory); diff --git a/src/DataProtection/DataProtection/src/Microsoft.AspNetCore.DataProtection.csproj b/src/DataProtection/DataProtection/src/Microsoft.AspNetCore.DataProtection.csproj index 8f16e33480..520a9f4745 100644 --- a/src/DataProtection/DataProtection/src/Microsoft.AspNetCore.DataProtection.csproj +++ b/src/DataProtection/DataProtection/src/Microsoft.AspNetCore.DataProtection.csproj @@ -1,4 +1,4 @@ - + ASP.NET Core logic to protect and unprotect data, similar to DPAPI. @@ -14,6 +14,8 @@ + diff --git a/src/DataProtection/DataProtection/src/RegistryPolicyResolver.cs b/src/DataProtection/DataProtection/src/RegistryPolicyResolver.cs index d3357fa34d..b1ec26ff12 100644 --- a/src/DataProtection/DataProtection/src/RegistryPolicyResolver.cs +++ b/src/DataProtection/DataProtection/src/RegistryPolicyResolver.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Reflection; +using System.Runtime.Versioning; using Microsoft.AspNetCore.Cryptography; using Microsoft.AspNetCore.DataProtection.AuthenticatedEncryption.ConfigurationModel; using Microsoft.AspNetCore.DataProtection.Internal; @@ -17,6 +18,7 @@ namespace Microsoft.AspNetCore.DataProtection /// /// A type which allows reading policy from the system registry. /// + [SupportedOSPlatform("windows")] internal sealed class RegistryPolicyResolver: IRegistryPolicyResolver { private readonly Func _getPolicyRegKey; diff --git a/src/DataProtection/DataProtection/src/Repositories/RegistryXmlRepository.cs b/src/DataProtection/DataProtection/src/Repositories/RegistryXmlRepository.cs index 7692d1ccb5..28a7cbec23 100644 --- a/src/DataProtection/DataProtection/src/Repositories/RegistryXmlRepository.cs +++ b/src/DataProtection/DataProtection/src/Repositories/RegistryXmlRepository.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using System.Globalization; using System.Linq; +using System.Runtime.Versioning; using System.Security.Principal; using System.Xml.Linq; using Microsoft.Extensions.Logging; @@ -15,6 +16,7 @@ namespace Microsoft.AspNetCore.DataProtection.Repositories /// /// An XML repository backed by the Windows registry. /// + [SupportedOSPlatform("windows")] public class RegistryXmlRepository : IXmlRepository { private static readonly Lazy _defaultRegistryKeyLazy = new Lazy(GetDefaultHklmStorageKey); diff --git a/src/DataProtection/DataProtection/src/XmlEncryption/DpapiNGXmlEncryptor.cs b/src/DataProtection/DataProtection/src/XmlEncryption/DpapiNGXmlEncryptor.cs index f5162496bb..edd3afd493 100644 --- a/src/DataProtection/DataProtection/src/XmlEncryption/DpapiNGXmlEncryptor.cs +++ b/src/DataProtection/DataProtection/src/XmlEncryption/DpapiNGXmlEncryptor.cs @@ -3,6 +3,7 @@ using System; using System.Globalization; +using System.Runtime.Versioning; using System.Security.Principal; using System.Xml.Linq; using Microsoft.AspNetCore.Cryptography; @@ -18,6 +19,7 @@ namespace Microsoft.AspNetCore.DataProtection.XmlEncryption /// /// This API is only supported on Windows 8 / Windows Server 2012 and higher. /// + [SupportedOSPlatform("windows")] public sealed class DpapiNGXmlEncryptor : IXmlEncryptor { private readonly ILogger _logger; diff --git a/src/DataProtection/DataProtection/src/XmlEncryption/DpapiXmlEncryptor.cs b/src/DataProtection/DataProtection/src/XmlEncryption/DpapiXmlEncryptor.cs index d7fa2d7b1b..cd842f1acd 100644 --- a/src/DataProtection/DataProtection/src/XmlEncryption/DpapiXmlEncryptor.cs +++ b/src/DataProtection/DataProtection/src/XmlEncryption/DpapiXmlEncryptor.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Runtime.Versioning; using System.Security.Principal; using System.Xml.Linq; using Microsoft.AspNetCore.Cryptography; @@ -16,6 +17,7 @@ namespace Microsoft.AspNetCore.DataProtection.XmlEncryption /// /// This API is only supported on Windows platforms. /// + [SupportedOSPlatform("windows")] public sealed class DpapiXmlEncryptor : IXmlEncryptor { private readonly ILogger _logger; diff --git a/src/Hosting/WindowsServices/src/Properties/AssemblyInfo.cs b/src/Hosting/WindowsServices/src/Properties/AssemblyInfo.cs index 63d95d6dfb..6e6ee3ba7f 100644 --- a/src/Hosting/WindowsServices/src/Properties/AssemblyInfo.cs +++ b/src/Hosting/WindowsServices/src/Properties/AssemblyInfo.cs @@ -2,5 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Runtime.CompilerServices; +using System.Runtime.Versioning; [assembly: InternalsVisibleTo("Microsoft.AspNetCore.Hosting.WindowsServices.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] +[assembly: SupportedOSPlatform("windows")] \ No newline at end of file diff --git a/src/Http/Http.Extensions/test/HeaderDictionaryTypeExtensionsTest.cs b/src/Http/Http.Extensions/test/HeaderDictionaryTypeExtensionsTest.cs index 06c0d967e6..2ca3c36e27 100644 --- a/src/Http/Http.Extensions/test/HeaderDictionaryTypeExtensionsTest.cs +++ b/src/Http/Http.Extensions/test/HeaderDictionaryTypeExtensionsTest.cs @@ -162,7 +162,7 @@ namespace Microsoft.AspNetCore.Http.Headers { public static bool TryParse(string value, out TestHeaderValue result) { - if (string.Equals("valid", value)) + if (string.Equals("valid", value, StringComparison.Ordinal)) { result = new TestHeaderValue(); return true; @@ -176,7 +176,7 @@ namespace Microsoft.AspNetCore.Http.Headers var results = new List(); foreach (var value in values) { - if (string.Equals("valid", value)) + if (string.Equals("valid", value, StringComparison.Ordinal)) { results.Add(new TestHeaderValue()); } diff --git a/src/Http/Routing/test/UnitTests/Template/TemplateParserTests.cs b/src/Http/Routing/test/UnitTests/Template/TemplateParserTests.cs index f5f36332e6..2ac022c212 100644 --- a/src/Http/Routing/test/UnitTests/Template/TemplateParserTests.cs +++ b/src/Http/Routing/test/UnitTests/Template/TemplateParserTests.cs @@ -896,7 +896,7 @@ namespace Microsoft.AspNetCore.Routing.Template.Tests foreach (var xconstraint in x.InlineConstraints) { if (!y.InlineConstraints.Any( - c => string.Equals(c.Constraint, xconstraint.Constraint))) + c => string.Equals(c.Constraint, xconstraint.Constraint, StringComparison.Ordinal))) { return false; } diff --git a/src/Razor/Microsoft.NET.Sdk.Razor/integrationtests/BuildIntrospectionTest.cs b/src/Razor/Microsoft.NET.Sdk.Razor/integrationtests/BuildIntrospectionTest.cs index de73ff376a..c857f59ee4 100644 --- a/src/Razor/Microsoft.NET.Sdk.Razor/integrationtests/BuildIntrospectionTest.cs +++ b/src/Razor/Microsoft.NET.Sdk.Razor/integrationtests/BuildIntrospectionTest.cs @@ -257,7 +257,7 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests Assert.BuildOutputContainsLine(result, $"RazorTasksPath: {expected}"); } - [ConditionalFact] + [ConditionalFact(Skip = "https://github.com/dotnet/aspnetcore/issues/24427")] [OSSkipCondition(OperatingSystems.Linux | OperatingSystems.MacOSX)] [InitializeTestProject("SimpleMvc")] public async Task IntrospectRazorTasksDllPath_DesktopMsBuild() diff --git a/src/Security/Authentication/Negotiate/src/NegotiateHandler.cs b/src/Security/Authentication/Negotiate/src/NegotiateHandler.cs index 0ef6697857..179a85ed0b 100644 --- a/src/Security/Authentication/Negotiate/src/NegotiateHandler.cs +++ b/src/Security/Authentication/Negotiate/src/NegotiateHandler.cs @@ -315,7 +315,7 @@ namespace Microsoft.AspNetCore.Authentication.Negotiate // things like ClaimsTransformation run per request. var identity = _negotiateState.GetIdentity(); ClaimsPrincipal user; - if (identity is WindowsIdentity winIdentity) + if (OperatingSystem.IsWindows() && identity is WindowsIdentity winIdentity) { user = new WindowsPrincipal(winIdentity); Response.RegisterForDispose(winIdentity); diff --git a/src/Servers/HttpSys/src/Microsoft.AspNetCore.Server.HttpSys.csproj b/src/Servers/HttpSys/src/Microsoft.AspNetCore.Server.HttpSys.csproj index 72b994fff3..0ab19cbe78 100644 --- a/src/Servers/HttpSys/src/Microsoft.AspNetCore.Server.HttpSys.csproj +++ b/src/Servers/HttpSys/src/Microsoft.AspNetCore.Server.HttpSys.csproj @@ -9,6 +9,9 @@ true aspnetcore;weblistener;httpsys false + + + $(NoWarn);CA1416 diff --git a/src/Servers/HttpSys/src/WebHostBuilderHttpSysExtensions.cs b/src/Servers/HttpSys/src/WebHostBuilderHttpSysExtensions.cs index f7c2b9445f..72ac78b014 100644 --- a/src/Servers/HttpSys/src/WebHostBuilderHttpSysExtensions.cs +++ b/src/Servers/HttpSys/src/WebHostBuilderHttpSysExtensions.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Runtime.Versioning; using Microsoft.AspNetCore.Hosting.Server; using Microsoft.AspNetCore.Server.HttpSys; using Microsoft.Extensions.DependencyInjection; @@ -11,7 +12,7 @@ namespace Microsoft.AspNetCore.Hosting { /// /// Provides extensions method to use Http.sys as the server for the web host. - /// + /// public static class WebHostBuilderHttpSysExtensions { /// @@ -23,6 +24,7 @@ namespace Microsoft.AspNetCore.Hosting /// /// A reference to the parameter object. /// + [SupportedOSPlatform("windows")] public static IWebHostBuilder UseHttpSys(this IWebHostBuilder hostBuilder) { return hostBuilder.ConfigureServices(services => { @@ -52,6 +54,7 @@ namespace Microsoft.AspNetCore.Hosting /// /// A reference to the parameter object. /// + [SupportedOSPlatform("windows")] public static IWebHostBuilder UseHttpSys(this IWebHostBuilder hostBuilder, Action options) { return hostBuilder.UseHttpSys().ConfigureServices(services => diff --git a/src/Servers/IIS/IIS/src/Microsoft.AspNetCore.Server.IIS.csproj b/src/Servers/IIS/IIS/src/Microsoft.AspNetCore.Server.IIS.csproj index d262f5cd0b..5727a00650 100644 --- a/src/Servers/IIS/IIS/src/Microsoft.AspNetCore.Server.IIS.csproj +++ b/src/Servers/IIS/IIS/src/Microsoft.AspNetCore.Server.IIS.csproj @@ -11,12 +11,15 @@ true $(DefaultNetCoreTargetFramework) false + + + $(NoWarn);CA1416 - + diff --git a/src/Servers/IIS/IISIntegration/src/Microsoft.AspNetCore.Server.IISIntegration.csproj b/src/Servers/IIS/IISIntegration/src/Microsoft.AspNetCore.Server.IISIntegration.csproj index addaf56ff2..0c1e8fb171 100644 --- a/src/Servers/IIS/IISIntegration/src/Microsoft.AspNetCore.Server.IISIntegration.csproj +++ b/src/Servers/IIS/IISIntegration/src/Microsoft.AspNetCore.Server.IISIntegration.csproj @@ -9,6 +9,9 @@ aspnetcore;iis true false + + + $(NoWarn);CA1416 diff --git a/src/Servers/IIS/IntegrationTesting.IIS/src/Microsoft.AspNetCore.Server.IntegrationTesting.IIS.csproj b/src/Servers/IIS/IntegrationTesting.IIS/src/Microsoft.AspNetCore.Server.IntegrationTesting.IIS.csproj index d98aab50da..148e9db98e 100644 --- a/src/Servers/IIS/IntegrationTesting.IIS/src/Microsoft.AspNetCore.Server.IntegrationTesting.IIS.csproj +++ b/src/Servers/IIS/IntegrationTesting.IIS/src/Microsoft.AspNetCore.Server.IntegrationTesting.IIS.csproj @@ -20,6 +20,8 @@ about this structure --> $(NoWarn);NU5100 + + $(NoWarn);CA1416 diff --git a/src/Servers/Kestrel/stress/Program.cs b/src/Servers/Kestrel/stress/Program.cs index c962d5bfd7..2a07813d71 100644 --- a/src/Servers/Kestrel/stress/Program.cs +++ b/src/Servers/Kestrel/stress/Program.cs @@ -646,7 +646,7 @@ public class Program { await stream.WriteAsync(new byte[] { 1, 2, 3 }); - var tcs = new TaskCompletionSource(TaskContinuationOptions.RunContinuationsAsynchronously); + var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); using (_cancellationToken.Register(() => tcs.SetResult(true))) { await tcs.Task.ConfigureAwait(false); diff --git a/src/Shared/CertificateGeneration/CertificateManager.cs b/src/Shared/CertificateGeneration/CertificateManager.cs index b5c0d0088e..8ad2e14749 100644 --- a/src/Shared/CertificateGeneration/CertificateManager.cs +++ b/src/Shared/CertificateGeneration/CertificateManager.cs @@ -28,7 +28,9 @@ namespace Microsoft.AspNetCore.Certificates.Generation public const int RSAMinimumKeySizeInBits = 2048; public static CertificateManager Instance { get; } = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? +#pragma warning disable CA1416 // Validate platform compatibility new WindowsCertificateManager() : +#pragma warning restore CA1416 // Validate platform compatibility RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? new MacOSCertificateManager() as CertificateManager : new UnixCertificateManager(); diff --git a/src/Shared/CertificateGeneration/WindowsCertificateManager.cs b/src/Shared/CertificateGeneration/WindowsCertificateManager.cs index cbeed665d2..e9fe0ef2e1 100644 --- a/src/Shared/CertificateGeneration/WindowsCertificateManager.cs +++ b/src/Shared/CertificateGeneration/WindowsCertificateManager.cs @@ -1,11 +1,13 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Runtime.Versioning; using System.Security.Cryptography; using System.Security.Cryptography.X509Certificates; namespace Microsoft.AspNetCore.Certificates.Generation { + [SupportedOSPlatform("windows")] internal class WindowsCertificateManager : CertificateManager { private const int UserCancelledErrorCode = 1223; diff --git a/src/Shared/PlatformAttributes.cs b/src/Shared/PlatformAttributes.cs new file mode 100644 index 0000000000..0d44154118 --- /dev/null +++ b/src/Shared/PlatformAttributes.cs @@ -0,0 +1,107 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +// Copied from https://raw.githubusercontent.com/dotnet/runtime/b45ee9d37afec0c88141053e86ccf71c6f283000/src/libraries/System.Private.CoreLib/src/System/Runtime/Versioning/PlatformAttributes.cs + +#nullable enable +namespace System.Runtime.Versioning +{ + /// + /// Base type for all platform-specific API attributes. + /// +#pragma warning disable CS3015 // Type has no accessible constructors which use only CLS-compliant types +#if SYSTEM_PRIVATE_CORELIB + public +#else + internal +#endif + abstract class OSPlatformAttribute : Attribute +#pragma warning restore CS3015 + { + private protected OSPlatformAttribute(string platformName) + { + PlatformName = platformName; + } + public string PlatformName { get; } + } + + /// + /// Records the platform that the project targeted. + /// + [AttributeUsage(AttributeTargets.Assembly, + AllowMultiple = false, Inherited = false)] +#if SYSTEM_PRIVATE_CORELIB + public +#else + internal +#endif + sealed class TargetPlatformAttribute : OSPlatformAttribute + { + public TargetPlatformAttribute(string platformName) : base(platformName) + { + } + } + + /// + /// Records the operating system (and minimum version) that supports an API. Multiple attributes can be + /// applied to indicate support on multiple operating systems. + /// + /// + /// Callers can apply a + /// or use guards to prevent calls to APIs on unsupported operating systems. + /// + /// A given platform should only be specified once. + /// + [AttributeUsage(AttributeTargets.Assembly | + AttributeTargets.Class | + AttributeTargets.Constructor | + AttributeTargets.Enum | + AttributeTargets.Event | + AttributeTargets.Field | + AttributeTargets.Method | + AttributeTargets.Module | + AttributeTargets.Property | + AttributeTargets.Struct, + AllowMultiple = true, Inherited = false)] +#if SYSTEM_PRIVATE_CORELIB + public +#else + internal +#endif + sealed class SupportedOSPlatformAttribute : OSPlatformAttribute + { + public SupportedOSPlatformAttribute (string platformName) : base(platformName) + { + } + } + + /// + /// Marks APIs that were removed in a given operating system version. + /// + /// + /// Primarily used by OS bindings to indicate APIs that are only available in + /// earlier versions. + /// + [AttributeUsage(AttributeTargets.Assembly | + AttributeTargets.Class | + AttributeTargets.Constructor | + AttributeTargets.Enum | + AttributeTargets.Event | + AttributeTargets.Field | + AttributeTargets.Method | + AttributeTargets.Module | + AttributeTargets.Property | + AttributeTargets.Struct, + AllowMultiple = true, Inherited = false)] +#if SYSTEM_PRIVATE_CORELIB + public +#else + internal +#endif + sealed class UnsupportedOSPlatformAttribute : OSPlatformAttribute + { + public UnsupportedOSPlatformAttribute(string platformName) : base(platformName) + { + } + } +} \ No newline at end of file diff --git a/src/Shared/test/Shared.Tests/runtime/Http2/HPackIntegerTest.cs b/src/Shared/test/Shared.Tests/runtime/Http2/HPackIntegerTest.cs index 98938a776b..704dad8ac4 100644 --- a/src/Shared/test/Shared.Tests/runtime/Http2/HPackIntegerTest.cs +++ b/src/Shared/test/Shared.Tests/runtime/Http2/HPackIntegerTest.cs @@ -55,12 +55,13 @@ namespace System.Net.Http.Unit.Tests.HPack public void IntegerEncoderDecoderRoundtrips() { IntegerDecoder decoder = new IntegerDecoder(); + Span integerBytes = stackalloc byte[5]; for (int i = 0; i < 2048; ++i) { for (int prefixLength = 1; prefixLength <= 8; ++prefixLength) { - Span integerBytes = stackalloc byte[5]; + integerBytes.Clear(); Assert.True(IntegerEncoder.Encode(i, prefixLength, integerBytes, out int length)); bool decodeResult = decoder.BeginTryDecode(integerBytes[0], prefixLength, out int intResult); diff --git a/src/SignalR/common/Http.Connections/src/Internal/HttpConnectionDispatcher.cs b/src/SignalR/common/Http.Connections/src/Internal/HttpConnectionDispatcher.cs index d20503d63e..7134abc1f9 100644 --- a/src/SignalR/common/Http.Connections/src/Internal/HttpConnectionDispatcher.cs +++ b/src/SignalR/common/Http.Connections/src/Internal/HttpConnectionDispatcher.cs @@ -580,7 +580,7 @@ namespace Microsoft.AspNetCore.Http.Connections.Internal if (oldContext.User.Identity is WindowsIdentity windowsIdentity) { var skipFirstIdentity = false; - if (oldContext.User is WindowsPrincipal) + if (OperatingSystem.IsWindows() && oldContext.User is WindowsPrincipal) { // We want to explicitly create a WindowsPrincipal instead of a ClaimsPrincipal // so methods that WindowsPrincipal overrides like 'IsInRole', work as expected.