From abc525d0c2a5b0be09e4d7e4c1e67571afb77c80 Mon Sep 17 00:00:00 2001 From: Buyaa Date: Wed, 25 Nov 2020 13:20:52 -0800 Subject: [PATCH] Handle unsupported browser warnings (#43363) * Handle browser warnings * Apply feedback, revert updates handled with different PRs * Add misssing diagnotic id * Address multitargeted warnings * Apply feedback * Small type/comment updates * Apply more feedback * Use project settings instead adding Directory.Build.props * Annotate APIs injecting unsupported type through DI * Fix window support related warnings found with generic type parameter * Fix another browser warning found with generic type parameter bug fix * All public APIs of ConsoleLoggerExtensions are unsupported, so marking entire type as unsupported on browser * Try handle mono warnings * Revert mono related changes, it was mistake * Try handle browser warninga in mono * Apply feedback and fix new warnings caused from corelib changes * Review update * Apply feedback * Move platform specific section from HttpTelemetry * Revering unwanted changes * Remove redundant attributes * Exclude cross platform build with browser target * small updates * Annotate entire type DiagnosticCounter unsupported * Apply feedback, improve suppression comments * Remove Unsupported browser from TypeDescriptor.CreateInstance, TypeDescriptionProvider.CreateInstance and related updates --- eng/versioning.targets | 9 ++ .../src/System/Net/WebSockets/ManagedWebSocket.cs | 2 + .../ref/Microsoft.Extensions.Logging.Console.cs | 2 + .../Microsoft.Extensions.Logging.Console.csproj | 1 + .../src/AnsiParsingLogConsole.cs | 2 + .../src/ConsoleLogger.cs | 2 + .../src/ConsoleLoggerExtensions.cs | 4 + .../src/ConsoleLoggerProcessor.cs | 2 + .../src/ConsoleLoggerProvider.cs | 2 + .../Microsoft.Extensions.Logging.Console.csproj | 3 +- .../ref/System.Collections.Concurrent.cs | 1 + .../Collections/Concurrent/BlockingCollection.cs | 3 + .../ref/System.ComponentModel.TypeConverter.cs | 2 - .../ComponentModel/TypeDescriptionProvider.cs | 1 - .../src/System/ComponentModel/TypeDescriptor.cs | 1 - .../System/Diagnostics/XmlWriterTraceListener.cs | 10 +- .../ref/System.Diagnostics.Tracing.Counters.cs | 5 + .../System.Linq.Parallel/Directory.Build.props | 1 + .../System.Net.Connections/Directory.Build.props | 1 + .../System.Net.Http/ref/System.Net.Http.cs | 1 + .../System.Net.Http/src/System.Net.Http.csproj | 8 +- .../BrowserHttpHandler/HttpTelemetry.Browser.cs | 22 +++++ .../src/System/Net/Http/HttpClient.cs | 2 + .../src/System/Net/Http/HttpClientHandler.cs | 1 + .../src/System/Net/Http/HttpTelemetry.AnyOS.cs | 104 +++++++++++++++++++++ .../src/System/Net/Http/HttpTelemetry.cs | 94 +------------------ .../ref/System.Net.ServicePoint.cs | 1 + .../src/System/Net/ServicePointManager.cs | 2 + .../System.Net.WebProxy/src/System/Net/WebProxy.cs | 4 + .../Directory.Build.props | 1 + .../ref/System.Net.WebSockets.WebSocketProtocol.cs | 1 + .../src/System/Net/WebSockets/WebSocketProtocol.cs | 2 + .../ref/System.Net.WebSockets.cs | 2 + .../src/System/Net/WebSockets/WebSocket.cs | 3 + .../src/System/Diagnostics/Tracing/CounterGroup.cs | 2 + .../Diagnostics/Tracing/DiagnosticCounter.cs | 2 + .../src/System/Diagnostics/Tracing/EventCounter.cs | 2 + .../Tracing/IncrementingEventCounter.cs | 5 + .../Tracing/IncrementingPollingCounter.cs | 5 + .../System/Diagnostics/Tracing/PollingCounter.cs | 5 + .../src/System/IO/FileStream.Unix.cs | 5 + .../System.Private.CoreLib/src/System/IO/Stream.cs | 4 + .../src/System/Threading/ManualResetEventSlim.cs | 7 ++ .../src/System/Threading/SemaphoreSlim.cs | 8 ++ .../src/System/Threading/Tasks/FutureFactory.cs | 2 + .../src/System/Threading/Tasks/Task.cs | 10 ++ .../Threading/Tasks/ThreadPoolTaskScheduler.cs | 2 + .../src/System/Xml/XmlDownloadManagerAsync.cs | 2 + .../src/System/Xml/XmlUrlResolver.cs | 2 + src/libraries/System.Runtime/ref/System.Runtime.cs | 5 + .../Directory.Build.props | 1 + .../ref/System.Security.Permissions.netcoreapp.cs | 1 + .../System/Xaml/Permissions/XamlLoadPermission.cs | 2 + .../src/System/Threading/Tasks/Parallel.cs | 2 + .../System.Threading/ref/System.Threading.cs | 31 ++++++ .../src/System/Threading/Barrier.cs | 10 ++ .../src/System/Threading/CountdownEvent.cs | 7 ++ .../src/System/Threading/ReaderWriterLock.cs | 7 ++ .../ref/System.Transactions.Local.cs | 2 + .../System/Transactions/CommittableTransaction.cs | 2 + .../src/System/Transactions/Transaction.cs | 4 + .../src/System/Transactions/TransactionScope.cs | 2 + .../ref/System.Xml.ReaderWriter.cs | 2 + .../System.Private.CoreLib.csproj | 7 +- 64 files changed, 343 insertions(+), 107 deletions(-) create mode 100644 src/libraries/System.Net.Http/src/System/Net/Http/BrowserHttpHandler/HttpTelemetry.Browser.cs create mode 100644 src/libraries/System.Net.Http/src/System/Net/Http/HttpTelemetry.AnyOS.cs diff --git a/eng/versioning.targets b/eng/versioning.targets index 3177b48..98fd08c 100644 --- a/eng/versioning.targets +++ b/eng/versioning.targets @@ -29,6 +29,15 @@ + + true + + + + + + + <_unsupportedOSPlatforms Include="$(UnsupportedOSPlatforms)" /> diff --git a/src/libraries/Common/src/System/Net/WebSockets/ManagedWebSocket.cs b/src/libraries/Common/src/System/Net/WebSockets/ManagedWebSocket.cs index 7ed7a15..cffafdd 100644 --- a/src/libraries/Common/src/System/Net/WebSockets/ManagedWebSocket.cs +++ b/src/libraries/Common/src/System/Net/WebSockets/ManagedWebSocket.cs @@ -7,6 +7,7 @@ using System.IO; using System.Numerics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; +using System.Runtime.Versioning; using System.Security.Cryptography; using System.Text; using System.Threading; @@ -23,6 +24,7 @@ namespace System.Net.WebSockets /// a send operation while another is in progress or a receive operation while another is in progress will /// result in an exception. /// + [UnsupportedOSPlatform("browser")] internal sealed partial class ManagedWebSocket : WebSocket { /// Creates a from a connected to a websocket endpoint. diff --git a/src/libraries/Microsoft.Extensions.Logging.Console/ref/Microsoft.Extensions.Logging.Console.cs b/src/libraries/Microsoft.Extensions.Logging.Console/ref/Microsoft.Extensions.Logging.Console.cs index 80e365a..4cca93a 100644 --- a/src/libraries/Microsoft.Extensions.Logging.Console/ref/Microsoft.Extensions.Logging.Console.cs +++ b/src/libraries/Microsoft.Extensions.Logging.Console/ref/Microsoft.Extensions.Logging.Console.cs @@ -6,6 +6,7 @@ namespace Microsoft.Extensions.Logging { + [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] public static partial class ConsoleLoggerExtensions { public static Microsoft.Extensions.Logging.ILoggingBuilder AddConsole(this Microsoft.Extensions.Logging.ILoggingBuilder builder) { throw null; } @@ -63,6 +64,7 @@ namespace Microsoft.Extensions.Logging.Console [System.ObsoleteAttribute("ConsoleLoggerOptions.UseUtcTimestamp has been deprecated. Please use ConsoleFormatterOptions.UseUtcTimestamp instead.", false)] public bool UseUtcTimestamp { get { throw null; } set { } } } + [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] [Microsoft.Extensions.Logging.ProviderAliasAttribute("Console")] public partial class ConsoleLoggerProvider : Microsoft.Extensions.Logging.ILoggerProvider, Microsoft.Extensions.Logging.ISupportExternalScope, System.IDisposable { diff --git a/src/libraries/Microsoft.Extensions.Logging.Console/ref/Microsoft.Extensions.Logging.Console.csproj b/src/libraries/Microsoft.Extensions.Logging.Console/ref/Microsoft.Extensions.Logging.Console.csproj index 048eb04..41c181e 100644 --- a/src/libraries/Microsoft.Extensions.Logging.Console/ref/Microsoft.Extensions.Logging.Console.csproj +++ b/src/libraries/Microsoft.Extensions.Logging.Console/ref/Microsoft.Extensions.Logging.Console.csproj @@ -1,6 +1,7 @@ netstandard2.0;net461 + true diff --git a/src/libraries/Microsoft.Extensions.Logging.Console/src/AnsiParsingLogConsole.cs b/src/libraries/Microsoft.Extensions.Logging.Console/src/AnsiParsingLogConsole.cs index 9f42ec6..6a44732 100644 --- a/src/libraries/Microsoft.Extensions.Logging.Console/src/AnsiParsingLogConsole.cs +++ b/src/libraries/Microsoft.Extensions.Logging.Console/src/AnsiParsingLogConsole.cs @@ -3,9 +3,11 @@ using System; using System.IO; +using System.Runtime.Versioning; namespace Microsoft.Extensions.Logging.Console { + [UnsupportedOSPlatform("browser")] internal class AnsiParsingLogConsole : IConsole { private readonly TextWriter _textWriter; diff --git a/src/libraries/Microsoft.Extensions.Logging.Console/src/ConsoleLogger.cs b/src/libraries/Microsoft.Extensions.Logging.Console/src/ConsoleLogger.cs index 1d544f3..daa903d 100644 --- a/src/libraries/Microsoft.Extensions.Logging.Console/src/ConsoleLogger.cs +++ b/src/libraries/Microsoft.Extensions.Logging.Console/src/ConsoleLogger.cs @@ -3,10 +3,12 @@ using System; using System.IO; +using System.Runtime.Versioning; using Microsoft.Extensions.Logging.Abstractions; namespace Microsoft.Extensions.Logging.Console { + [UnsupportedOSPlatform("browser")] internal class ConsoleLogger : ILogger { private readonly string _name; diff --git a/src/libraries/Microsoft.Extensions.Logging.Console/src/ConsoleLoggerExtensions.cs b/src/libraries/Microsoft.Extensions.Logging.Console/src/ConsoleLoggerExtensions.cs index 8cd8a59..9d12ac5 100644 --- a/src/libraries/Microsoft.Extensions.Logging.Console/src/ConsoleLoggerExtensions.cs +++ b/src/libraries/Microsoft.Extensions.Logging.Console/src/ConsoleLoggerExtensions.cs @@ -3,6 +3,7 @@ using System; using System.Diagnostics.CodeAnalysis; +using System.Runtime.Versioning; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; @@ -12,6 +13,7 @@ using Microsoft.Extensions.Options; namespace Microsoft.Extensions.Logging { + [UnsupportedOSPlatform("browser")] public static class ConsoleLoggerExtensions { /// @@ -154,6 +156,7 @@ namespace Microsoft.Extensions.Logging } } + [UnsupportedOSPlatform("browser")] internal class ConsoleLoggerFormatterConfigureOptions : ConfigureFromConfigurationOptions where TOptions : ConsoleFormatterOptions where TFormatter : ConsoleFormatter @@ -164,6 +167,7 @@ namespace Microsoft.Extensions.Logging } } + [UnsupportedOSPlatform("browser")] internal class ConsoleLoggerFormatterOptionsChangeTokenSource : ConfigurationChangeTokenSource where TOptions : ConsoleFormatterOptions where TFormatter : ConsoleFormatter diff --git a/src/libraries/Microsoft.Extensions.Logging.Console/src/ConsoleLoggerProcessor.cs b/src/libraries/Microsoft.Extensions.Logging.Console/src/ConsoleLoggerProcessor.cs index 83a49c2..c79ccac 100644 --- a/src/libraries/Microsoft.Extensions.Logging.Console/src/ConsoleLoggerProcessor.cs +++ b/src/libraries/Microsoft.Extensions.Logging.Console/src/ConsoleLoggerProcessor.cs @@ -3,10 +3,12 @@ using System; using System.Collections.Concurrent; +using System.Runtime.Versioning; using System.Threading; namespace Microsoft.Extensions.Logging.Console { + [UnsupportedOSPlatform("browser")] internal class ConsoleLoggerProcessor : IDisposable { private const int _maxQueuedMessages = 1024; diff --git a/src/libraries/Microsoft.Extensions.Logging.Console/src/ConsoleLoggerProvider.cs b/src/libraries/Microsoft.Extensions.Logging.Console/src/ConsoleLoggerProvider.cs index 7a8f613..fd995f7 100644 --- a/src/libraries/Microsoft.Extensions.Logging.Console/src/ConsoleLoggerProvider.cs +++ b/src/libraries/Microsoft.Extensions.Logging.Console/src/ConsoleLoggerProvider.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Runtime.InteropServices; +using System.Runtime.Versioning; using Microsoft.Extensions.Options; namespace Microsoft.Extensions.Logging.Console @@ -12,6 +13,7 @@ namespace Microsoft.Extensions.Logging.Console /// /// A provider of instances. /// + [UnsupportedOSPlatform("browser")] [ProviderAlias("Console")] public class ConsoleLoggerProvider : ILoggerProvider, ISupportExternalScope { diff --git a/src/libraries/Microsoft.Extensions.Logging.Console/src/Microsoft.Extensions.Logging.Console.csproj b/src/libraries/Microsoft.Extensions.Logging.Console/src/Microsoft.Extensions.Logging.Console.csproj index 1e8e0f4..ef573cd 100644 --- a/src/libraries/Microsoft.Extensions.Logging.Console/src/Microsoft.Extensions.Logging.Console.csproj +++ b/src/libraries/Microsoft.Extensions.Logging.Console/src/Microsoft.Extensions.Logging.Console.csproj @@ -1,4 +1,4 @@ - + $(NetCoreAppCurrent);netcoreapp3.0;netstandard2.0;net461 @@ -8,6 +8,7 @@ $(DefineConstants);NO_SUPPRESS_GC_TRANSITION false + true diff --git a/src/libraries/System.Collections.Concurrent/ref/System.Collections.Concurrent.cs b/src/libraries/System.Collections.Concurrent/ref/System.Collections.Concurrent.cs index c1a477b..a7955b0 100644 --- a/src/libraries/System.Collections.Concurrent/ref/System.Collections.Concurrent.cs +++ b/src/libraries/System.Collections.Concurrent/ref/System.Collections.Concurrent.cs @@ -6,6 +6,7 @@ namespace System.Collections.Concurrent { + [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] public partial class BlockingCollection : System.Collections.Generic.IEnumerable, System.Collections.Generic.IReadOnlyCollection, System.Collections.ICollection, System.Collections.IEnumerable, System.IDisposable { public BlockingCollection() { } diff --git a/src/libraries/System.Collections.Concurrent/src/System/Collections/Concurrent/BlockingCollection.cs b/src/libraries/System.Collections.Concurrent/src/System/Collections/Concurrent/BlockingCollection.cs index 40dc971..3640d0d 100644 --- a/src/libraries/System.Collections.Concurrent/src/System/Collections/Concurrent/BlockingCollection.cs +++ b/src/libraries/System.Collections.Concurrent/src/System/Collections/Concurrent/BlockingCollection.cs @@ -15,6 +15,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.Globalization; +using System.Runtime.Versioning; using System.Threading; namespace System.Collections.Concurrent @@ -38,6 +39,7 @@ namespace System.Collections.Concurrent /// away as an . /// /// Specifies the type of elements in the collection. + [UnsupportedOSPlatform("browser")] [DebuggerTypeProxy(typeof(BlockingCollectionDebugView<>))] [DebuggerDisplay("Count = {Count}, Type = {_collection}")] public class BlockingCollection : IEnumerable, ICollection, IDisposable, IReadOnlyCollection @@ -1801,6 +1803,7 @@ namespace System.Collections.Concurrent } /// Returns a snapshot of the underlying collection's elements. + [UnsupportedOSPlatform("browser")] [DebuggerBrowsable(DebuggerBrowsableState.RootHidden)] public T[] Items { diff --git a/src/libraries/System.ComponentModel.TypeConverter/ref/System.ComponentModel.TypeConverter.cs b/src/libraries/System.ComponentModel.TypeConverter/ref/System.ComponentModel.TypeConverter.cs index ff1082f..d741db0 100644 --- a/src/libraries/System.ComponentModel.TypeConverter/ref/System.ComponentModel.TypeConverter.cs +++ b/src/libraries/System.ComponentModel.TypeConverter/ref/System.ComponentModel.TypeConverter.cs @@ -1309,7 +1309,6 @@ namespace System.ComponentModel { protected TypeDescriptionProvider() { } protected TypeDescriptionProvider(System.ComponentModel.TypeDescriptionProvider parent) { } - [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public virtual object CreateInstance(System.IServiceProvider provider, System.Type objectType, System.Type[] argTypes, object[] args) { throw null; } public virtual System.Collections.IDictionary GetCache(object instance) { throw null; } public virtual System.ComponentModel.ICustomTypeDescriptor GetExtendedTypeDescriptor(object instance) { throw null; } @@ -1352,7 +1351,6 @@ namespace System.ComponentModel public static System.ComponentModel.Design.IDesigner CreateDesigner(System.ComponentModel.IComponent component, System.Type designerBaseType) { throw null; } public static System.ComponentModel.EventDescriptor CreateEvent(System.Type componentType, System.ComponentModel.EventDescriptor oldEventDescriptor, params System.Attribute[] attributes) { throw null; } public static System.ComponentModel.EventDescriptor CreateEvent(System.Type componentType, string name, System.Type type, params System.Attribute[] attributes) { throw null; } - [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public static object CreateInstance(System.IServiceProvider provider, System.Type objectType, System.Type[] argTypes, object[] args) { throw null; } public static System.ComponentModel.PropertyDescriptor CreateProperty(System.Type componentType, System.ComponentModel.PropertyDescriptor oldPropertyDescriptor, params System.Attribute[] attributes) { throw null; } public static System.ComponentModel.PropertyDescriptor CreateProperty(System.Type componentType, string name, System.Type type, params System.Attribute[] attributes) { throw null; } diff --git a/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/TypeDescriptionProvider.cs b/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/TypeDescriptionProvider.cs index 565bc42..28b7a3a 100644 --- a/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/TypeDescriptionProvider.cs +++ b/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/TypeDescriptionProvider.cs @@ -50,7 +50,6 @@ namespace System.ComponentModel /// parent provider was passed. If a parent provider was passed, this /// method will invoke the parent provider's CreateInstance method. /// - [UnsupportedOSPlatform("browser")] public virtual object CreateInstance(IServiceProvider provider, Type objectType, Type[] argTypes, object[] args) { if (_parent != null) diff --git a/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/TypeDescriptor.cs b/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/TypeDescriptor.cs index a542eb2..0dc2b32 100644 --- a/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/TypeDescriptor.cs +++ b/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/TypeDescriptor.cs @@ -429,7 +429,6 @@ namespace System.ComponentModel /// a TypeDescriptionProvider object that is associated with the given /// data type. If it finds one, it will delegate the call to that object. /// - [UnsupportedOSPlatform("browser")] public static object CreateInstance(IServiceProvider provider, Type objectType, Type[] argTypes, object[] args) { if (objectType == null) diff --git a/src/libraries/System.Diagnostics.TextWriterTraceListener/src/System/Diagnostics/XmlWriterTraceListener.cs b/src/libraries/System.Diagnostics.TextWriterTraceListener/src/System/Diagnostics/XmlWriterTraceListener.cs index bf97f5f..798968d 100644 --- a/src/libraries/System.Diagnostics.TextWriterTraceListener/src/System/Diagnostics/XmlWriterTraceListener.cs +++ b/src/libraries/System.Diagnostics.TextWriterTraceListener/src/System/Diagnostics/XmlWriterTraceListener.cs @@ -258,14 +258,14 @@ namespace System.Diagnostics string? processName = s_processName; if (processName is null) { - try + if (OperatingSystem.IsBrowser()) // Process isn't supported on Browser { - using Process process = Process.GetCurrentProcess(); - s_processName = processName = process.ProcessName; + s_processName = processName = string.Empty; } - catch (PlatformNotSupportedException) // Process isn't supported on Browser + else { - s_processName = processName = string.Empty; + using Process process = Process.GetCurrentProcess(); + s_processName = processName = process.ProcessName; } } diff --git a/src/libraries/System.Diagnostics.Tracing/ref/System.Diagnostics.Tracing.Counters.cs b/src/libraries/System.Diagnostics.Tracing/ref/System.Diagnostics.Tracing.Counters.cs index 2e1cce9..56c748f 100644 --- a/src/libraries/System.Diagnostics.Tracing/ref/System.Diagnostics.Tracing.Counters.cs +++ b/src/libraries/System.Diagnostics.Tracing/ref/System.Diagnostics.Tracing.Counters.cs @@ -3,6 +3,7 @@ namespace System.Diagnostics.Tracing { + [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] public abstract partial class DiagnosticCounter : System.IDisposable { internal DiagnosticCounter() { } @@ -13,11 +14,13 @@ namespace System.Diagnostics.Tracing public void AddMetadata(string key, string? value) { } public void Dispose() { } } + [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] public partial class PollingCounter : System.Diagnostics.Tracing.DiagnosticCounter { public PollingCounter(string name, System.Diagnostics.Tracing.EventSource eventSource, System.Func metricProvider) { } public override string ToString() { throw null; } } + [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] public partial class IncrementingEventCounter : System.Diagnostics.Tracing.DiagnosticCounter { public IncrementingEventCounter(string name, System.Diagnostics.Tracing.EventSource eventSource) { } @@ -25,12 +28,14 @@ namespace System.Diagnostics.Tracing public void Increment(double increment = 1) { } public override string ToString() { throw null; } } + [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] public partial class IncrementingPollingCounter : System.Diagnostics.Tracing.DiagnosticCounter { public IncrementingPollingCounter(string name, System.Diagnostics.Tracing.EventSource eventSource, System.Func totalValueProvider) { } public System.TimeSpan DisplayRateTimeScale { get { throw null; } set { } } public override string ToString() { throw null; } } + [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] public partial class EventCounter : System.Diagnostics.Tracing.DiagnosticCounter { public EventCounter(string name, System.Diagnostics.Tracing.EventSource eventSource) { } diff --git a/src/libraries/System.Linq.Parallel/Directory.Build.props b/src/libraries/System.Linq.Parallel/Directory.Build.props index e8d6554..7c0e0c2 100644 --- a/src/libraries/System.Linq.Parallel/Directory.Build.props +++ b/src/libraries/System.Linq.Parallel/Directory.Build.props @@ -2,5 +2,6 @@ Microsoft + browser diff --git a/src/libraries/System.Net.Connections/Directory.Build.props b/src/libraries/System.Net.Connections/Directory.Build.props index 63f02a0..0a5c846 100644 --- a/src/libraries/System.Net.Connections/Directory.Build.props +++ b/src/libraries/System.Net.Connections/Directory.Build.props @@ -2,5 +2,6 @@ Microsoft + browser \ No newline at end of file diff --git a/src/libraries/System.Net.Http/ref/System.Net.Http.cs b/src/libraries/System.Net.Http/ref/System.Net.Http.cs index 35406af..d38fc45 100644 --- a/src/libraries/System.Net.Http/ref/System.Net.Http.cs +++ b/src/libraries/System.Net.Http/ref/System.Net.Http.cs @@ -118,6 +118,7 @@ namespace System.Net.Http public System.Net.CookieContainer CookieContainer { get { throw null; } set { } } [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public System.Net.ICredentials? Credentials { get { throw null; } set { } } + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public static System.Func DangerousAcceptAnyServerCertificateValidator { get { throw null; } } [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public System.Net.ICredentials? DefaultProxyCredentials { get { throw null; } set { } } diff --git a/src/libraries/System.Net.Http/src/System.Net.Http.csproj b/src/libraries/System.Net.Http/src/System.Net.Http.csproj index 70c8da7..13f7c27 100644 --- a/src/libraries/System.Net.Http/src/System.Net.Http.csproj +++ b/src/libraries/System.Net.Http/src/System.Net.Http.csproj @@ -1,4 +1,4 @@ - + win true @@ -106,8 +106,6 @@ - + + + diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/BrowserHttpHandler/HttpTelemetry.Browser.cs b/src/libraries/System.Net.Http/src/System/Net/Http/BrowserHttpHandler/HttpTelemetry.Browser.cs new file mode 100644 index 0000000..406afd1 --- /dev/null +++ b/src/libraries/System.Net.Http/src/System/Net/Http/BrowserHttpHandler/HttpTelemetry.Browser.cs @@ -0,0 +1,22 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Diagnostics.Tracing; + +namespace System.Net.Http +{ + internal sealed partial class HttpTelemetry + { + public void Http11RequestLeftQueue(double timeOnQueueMilliseconds) + { + } + + public void Http20RequestLeftQueue(double timeOnQueueMilliseconds) + { + } + + protected override void OnEventCommand(EventCommandEventArgs command) + { + } + } +} diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/HttpClient.cs b/src/libraries/System.Net.Http/src/System/Net/Http/HttpClient.cs index 807bab6..5b81865 100644 --- a/src/libraries/System.Net.Http/src/System/Net/Http/HttpClient.cs +++ b/src/libraries/System.Net.Http/src/System/Net/Http/HttpClient.cs @@ -511,7 +511,9 @@ namespace System.Net.Http // Wait for the send request to complete, getting back the response. response = async ? await base.SendAsync(request, cts.Token).ConfigureAwait(false) : +#pragma warning disable CA1416 // Validate platform compatibility, not supported on browser, safe to suppress base.Send(request, cts.Token); +#pragma warning restore CA1416 ThrowForNullResponse(response); // Buffer the response content if we've been asked to. diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/HttpClientHandler.cs b/src/libraries/System.Net.Http/src/System/Net/Http/HttpClientHandler.cs index 81de5ba..2e32896 100644 --- a/src/libraries/System.Net.Http/src/System/Net/Http/HttpClientHandler.cs +++ b/src/libraries/System.Net.Http/src/System/Net/Http/HttpClientHandler.cs @@ -306,6 +306,7 @@ namespace System.Net.Http // lazy-load the validator func so it can be trimmed by the ILLinker if it isn't used. private static Func? s_dangerousAcceptAnyServerCertificateValidator; + [UnsupportedOSPlatform("browser")] public static Func DangerousAcceptAnyServerCertificateValidator => Volatile.Read(ref s_dangerousAcceptAnyServerCertificateValidator) ?? Interlocked.CompareExchange(ref s_dangerousAcceptAnyServerCertificateValidator, delegate { return true; }, null) ?? diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/HttpTelemetry.AnyOS.cs b/src/libraries/System.Net.Http/src/System/Net/Http/HttpTelemetry.AnyOS.cs new file mode 100644 index 0000000..0a7e908 --- /dev/null +++ b/src/libraries/System.Net.Http/src/System/Net/Http/HttpTelemetry.AnyOS.cs @@ -0,0 +1,104 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Diagnostics; +using System.Diagnostics.Tracing; +using System.Threading; + +namespace System.Net.Http +{ + internal sealed partial class HttpTelemetry + { + private IncrementingPollingCounter? _startedRequestsPerSecondCounter; + private IncrementingPollingCounter? _failedRequestsPerSecondCounter; + private PollingCounter? _startedRequestsCounter; + private PollingCounter? _currentRequestsCounter; + private PollingCounter? _failedRequestsCounter; + private PollingCounter? _totalHttp11ConnectionsCounter; + private PollingCounter? _totalHttp20ConnectionsCounter; + private EventCounter? _http11RequestsQueueDurationCounter; + private EventCounter? _http20RequestsQueueDurationCounter; + + [NonEvent] + public void Http11RequestLeftQueue(double timeOnQueueMilliseconds) + { + _http11RequestsQueueDurationCounter!.WriteMetric(timeOnQueueMilliseconds); + RequestLeftQueue(timeOnQueueMilliseconds, versionMajor: 1, versionMinor: 1); + } + + [NonEvent] + public void Http20RequestLeftQueue(double timeOnQueueMilliseconds) + { + _http20RequestsQueueDurationCounter!.WriteMetric(timeOnQueueMilliseconds); + RequestLeftQueue(timeOnQueueMilliseconds, versionMajor: 2, versionMinor: 0); + } + + protected override void OnEventCommand(EventCommandEventArgs command) + { + if (command.Command == EventCommand.Enable) + { + // This is the convention for initializing counters in the RuntimeEventSource (lazily on the first enable command). + // They aren't disabled afterwards... + + // The cumulative number of HTTP requests started since the process started. + _startedRequestsCounter ??= new PollingCounter("requests-started", this, () => Interlocked.Read(ref _startedRequests)) + { + DisplayName = "Requests Started", + }; + + // The number of HTTP requests started per second since the process started. + _startedRequestsPerSecondCounter ??= new IncrementingPollingCounter("requests-started-rate", this, () => Interlocked.Read(ref _startedRequests)) + { + DisplayName = "Requests Started Rate", + DisplayRateTimeScale = TimeSpan.FromSeconds(1) + }; + + // The cumulative number of HTTP requests failed since the process started. + // Failed means that an exception occurred during the handler's Send(Async) call as a result of a connection related error, timeout, or explicitly cancelled. + // In case of using HttpClient's SendAsync(and friends) with buffering, this includes exceptions that occured while buffering the response content + // In case of using HttpClient's helper methods (GetString/ByteArray/Stream), this includes responses with non-success status codes + _failedRequestsCounter ??= new PollingCounter("requests-failed", this, () => Interlocked.Read(ref _failedRequests)) + { + DisplayName = "Requests Failed" + }; + + // The number of HTTP requests failed per second since the process started. + _failedRequestsPerSecondCounter ??= new IncrementingPollingCounter("requests-failed-rate", this, () => Interlocked.Read(ref _failedRequests)) + { + DisplayName = "Requests Failed Rate", + DisplayRateTimeScale = TimeSpan.FromSeconds(1) + }; + + // The current number of active HTTP requests that have started but not yet completed or failed. + // Use (-_stoppedRequests + _startedRequests) to avoid returning a negative value if _stoppedRequests is + // incremented after reading _startedRequests due to race conditions with completing the HTTP request. + _currentRequestsCounter ??= new PollingCounter("current-requests", this, () => -Interlocked.Read(ref _stoppedRequests) + Interlocked.Read(ref _startedRequests)) + { + DisplayName = "Current Requests" + }; + + _totalHttp11ConnectionsCounter ??= new PollingCounter("http11-connections-current-total", this, () => Interlocked.Read(ref _openedHttp11Connections)) + { + DisplayName = "Current Http 1.1 Connections" + }; + + _totalHttp20ConnectionsCounter ??= new PollingCounter("http20-connections-current-total", this, () => Interlocked.Read(ref _openedHttp20Connections)) + { + DisplayName = "Current Http 2.0 Connections" + }; + + _http11RequestsQueueDurationCounter ??= new EventCounter("http11-requests-queue-duration", this) + { + DisplayName = "HTTP 1.1 Requests Queue Duration", + DisplayUnits = "ms" + }; + + _http20RequestsQueueDurationCounter ??= new EventCounter("http20-requests-queue-duration", this) + { + DisplayName = "HTTP 2.0 Requests Queue Duration", + DisplayUnits = "ms" + }; + } + } + } +} diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/HttpTelemetry.cs b/src/libraries/System.Net.Http/src/System/Net/Http/HttpTelemetry.cs index 5879581..385d959 100644 --- a/src/libraries/System.Net.Http/src/System/Net/Http/HttpTelemetry.cs +++ b/src/libraries/System.Net.Http/src/System/Net/Http/HttpTelemetry.cs @@ -8,20 +8,10 @@ using System.Threading; namespace System.Net.Http { [EventSource(Name = "System.Net.Http")] - internal sealed class HttpTelemetry : EventSource + internal sealed partial class HttpTelemetry : EventSource { public static readonly HttpTelemetry Log = new HttpTelemetry(); - private IncrementingPollingCounter? _startedRequestsPerSecondCounter; - private IncrementingPollingCounter? _failedRequestsPerSecondCounter; - private PollingCounter? _startedRequestsCounter; - private PollingCounter? _currentRequestsCounter; - private PollingCounter? _failedRequestsCounter; - private PollingCounter? _totalHttp11ConnectionsCounter; - private PollingCounter? _totalHttp20ConnectionsCounter; - private EventCounter? _http11RequestsQueueDurationCounter; - private EventCounter? _http20RequestsQueueDurationCounter; - private long _startedRequests; private long _stoppedRequests; private long _failedRequests; @@ -169,88 +159,6 @@ namespace System.Net.Http } [NonEvent] - public void Http11RequestLeftQueue(double timeOnQueueMilliseconds) - { - _http11RequestsQueueDurationCounter!.WriteMetric(timeOnQueueMilliseconds); - RequestLeftQueue(timeOnQueueMilliseconds, versionMajor: 1, versionMinor: 1); - } - - [NonEvent] - public void Http20RequestLeftQueue(double timeOnQueueMilliseconds) - { - _http20RequestsQueueDurationCounter!.WriteMetric(timeOnQueueMilliseconds); - RequestLeftQueue(timeOnQueueMilliseconds, versionMajor: 2, versionMinor: 0); - } - - protected override void OnEventCommand(EventCommandEventArgs command) - { - if (command.Command == EventCommand.Enable) - { - // This is the convention for initializing counters in the RuntimeEventSource (lazily on the first enable command). - // They aren't disabled afterwards... - - // The cumulative number of HTTP requests started since the process started. - _startedRequestsCounter ??= new PollingCounter("requests-started", this, () => Interlocked.Read(ref _startedRequests)) - { - DisplayName = "Requests Started", - }; - - // The number of HTTP requests started per second since the process started. - _startedRequestsPerSecondCounter ??= new IncrementingPollingCounter("requests-started-rate", this, () => Interlocked.Read(ref _startedRequests)) - { - DisplayName = "Requests Started Rate", - DisplayRateTimeScale = TimeSpan.FromSeconds(1) - }; - - // The cumulative number of HTTP requests failed since the process started. - // Failed means that an exception occurred during the handler's Send(Async) call as a result of a connection related error, timeout, or explicitly cancelled. - // In case of using HttpClient's SendAsync(and friends) with buffering, this includes exceptions that occured while buffering the response content - // In case of using HttpClient's helper methods (GetString/ByteArray/Stream), this includes responses with non-success status codes - _failedRequestsCounter ??= new PollingCounter("requests-failed", this, () => Interlocked.Read(ref _failedRequests)) - { - DisplayName = "Requests Failed" - }; - - // The number of HTTP requests failed per second since the process started. - _failedRequestsPerSecondCounter ??= new IncrementingPollingCounter("requests-failed-rate", this, () => Interlocked.Read(ref _failedRequests)) - { - DisplayName = "Requests Failed Rate", - DisplayRateTimeScale = TimeSpan.FromSeconds(1) - }; - - // The current number of active HTTP requests that have started but not yet completed or failed. - // Use (-_stoppedRequests + _startedRequests) to avoid returning a negative value if _stoppedRequests is - // incremented after reading _startedRequests due to race conditions with completing the HTTP request. - _currentRequestsCounter ??= new PollingCounter("current-requests", this, () => -Interlocked.Read(ref _stoppedRequests) + Interlocked.Read(ref _startedRequests)) - { - DisplayName = "Current Requests" - }; - - _totalHttp11ConnectionsCounter ??= new PollingCounter("http11-connections-current-total", this, () => Interlocked.Read(ref _openedHttp11Connections)) - { - DisplayName = "Current Http 1.1 Connections" - }; - - _totalHttp20ConnectionsCounter ??= new PollingCounter("http20-connections-current-total", this, () => Interlocked.Read(ref _openedHttp20Connections)) - { - DisplayName = "Current Http 2.0 Connections" - }; - - _http11RequestsQueueDurationCounter ??= new EventCounter("http11-requests-queue-duration", this) - { - DisplayName = "HTTP 1.1 Requests Queue Duration", - DisplayUnits = "ms" - }; - - _http20RequestsQueueDurationCounter ??= new EventCounter("http20-requests-queue-duration", this) - { - DisplayName = "HTTP 2.0 Requests Queue Duration", - DisplayUnits = "ms" - }; - } - } - - [NonEvent] private unsafe void WriteEvent(int eventId, string? arg1, string? arg2, int arg3, string? arg4, byte arg5, byte arg6, HttpVersionPolicy arg7) { if (IsEnabled()) diff --git a/src/libraries/System.Net.ServicePoint/ref/System.Net.ServicePoint.cs b/src/libraries/System.Net.ServicePoint/ref/System.Net.ServicePoint.cs index d7adfc5..f26d234 100644 --- a/src/libraries/System.Net.ServicePoint/ref/System.Net.ServicePoint.cs +++ b/src/libraries/System.Net.ServicePoint/ref/System.Net.ServicePoint.cs @@ -48,6 +48,7 @@ namespace System.Net public static int DefaultConnectionLimit { get { throw null; } set { } } public static int DnsRefreshTimeout { get { throw null; } set { } } public static bool EnableDnsRoundRobin { get { throw null; } set { } } + [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] public static System.Net.Security.EncryptionPolicy EncryptionPolicy { get { throw null; } } public static bool Expect100Continue { get { throw null; } set { } } public static int MaxServicePointIdleTime { get { throw null; } set { } } diff --git a/src/libraries/System.Net.ServicePoint/src/System/Net/ServicePointManager.cs b/src/libraries/System.Net.ServicePoint/src/System/Net/ServicePointManager.cs index 267610d..eb278644 100644 --- a/src/libraries/System.Net.ServicePoint/src/System/Net/ServicePointManager.cs +++ b/src/libraries/System.Net.ServicePoint/src/System/Net/ServicePointManager.cs @@ -4,6 +4,7 @@ using System.Collections.Concurrent; using System.Collections.Generic; using System.Net.Security; +using System.Runtime.Versioning; using System.Threading; namespace System.Net @@ -102,6 +103,7 @@ namespace System.Net public static bool CheckCertificateRevocationList { get; set; } + [UnsupportedOSPlatform("browser")] public static EncryptionPolicy EncryptionPolicy { get; } = EncryptionPolicy.RequireEncryption; [Obsolete(Obsoletions.WebRequestMessage, DiagnosticId = Obsoletions.WebRequestDiagId, UrlFormat = Obsoletions.SharedUrlFormat)] diff --git a/src/libraries/System.Net.WebProxy/src/System/Net/WebProxy.cs b/src/libraries/System.Net.WebProxy/src/System/Net/WebProxy.cs index b853be8..a5db1a0 100644 --- a/src/libraries/System.Net.WebProxy/src/System/Net/WebProxy.cs +++ b/src/libraries/System.Net.WebProxy/src/System/Net/WebProxy.cs @@ -6,6 +6,7 @@ using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.Net.NetworkInformation; using System.Runtime.Serialization; +using System.Runtime.Versioning; using System.Text.RegularExpressions; namespace System.Net @@ -160,6 +161,7 @@ namespace System.Net string hostString = host.Host; +#pragma warning disable CA1416 // Validate platform compatibility, issue: https://github.com/dotnet/runtime/issues/43751 if (IPAddress.TryParse(hostString, out IPAddress? hostAddress)) { return IPAddress.IsLoopback(hostAddress) || IsAddressLocal(hostAddress); @@ -174,11 +176,13 @@ namespace System.Net // If it matches the primary domain, it's local. (Whether or not the hostname matches.) string local = "." + IPGlobalProperties.GetIPGlobalProperties().DomainName; +#pragma warning restore CA1416 // Validate platform compatibility return local.Length == (hostString.Length - dot) && string.Compare(local, 0, hostString, dot, local.Length, StringComparison.OrdinalIgnoreCase) == 0; } + [UnsupportedOSPlatform("browser")] private static bool IsAddressLocal(IPAddress ipAddress) { // Perf note: The .NET Framework caches this and then uses network change notifications to track diff --git a/src/libraries/System.Net.WebSockets.WebSocketProtocol/Directory.Build.props b/src/libraries/System.Net.WebSockets.WebSocketProtocol/Directory.Build.props index bdcfca3..1db5968 100644 --- a/src/libraries/System.Net.WebSockets.WebSocketProtocol/Directory.Build.props +++ b/src/libraries/System.Net.WebSockets.WebSocketProtocol/Directory.Build.props @@ -2,5 +2,6 @@ Open + true \ No newline at end of file diff --git a/src/libraries/System.Net.WebSockets.WebSocketProtocol/ref/System.Net.WebSockets.WebSocketProtocol.cs b/src/libraries/System.Net.WebSockets.WebSocketProtocol/ref/System.Net.WebSockets.WebSocketProtocol.cs index 7b6113f..295705f 100644 --- a/src/libraries/System.Net.WebSockets.WebSocketProtocol/ref/System.Net.WebSockets.WebSocketProtocol.cs +++ b/src/libraries/System.Net.WebSockets.WebSocketProtocol/ref/System.Net.WebSockets.WebSocketProtocol.cs @@ -6,6 +6,7 @@ namespace System.Net.WebSockets { + [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] public static partial class WebSocketProtocol { public static System.Net.WebSockets.WebSocket CreateFromStream(System.IO.Stream stream, bool isServer, string? subProtocol, System.TimeSpan keepAliveInterval) { throw null; } diff --git a/src/libraries/System.Net.WebSockets.WebSocketProtocol/src/System/Net/WebSockets/WebSocketProtocol.cs b/src/libraries/System.Net.WebSockets.WebSocketProtocol/src/System/Net/WebSockets/WebSocketProtocol.cs index 49e3196..1178e70 100644 --- a/src/libraries/System.Net.WebSockets.WebSocketProtocol/src/System/Net/WebSockets/WebSocketProtocol.cs +++ b/src/libraries/System.Net.WebSockets.WebSocketProtocol/src/System/Net/WebSockets/WebSocketProtocol.cs @@ -2,10 +2,12 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.IO; +using System.Runtime.Versioning; using System.Threading; namespace System.Net.WebSockets { + [UnsupportedOSPlatform("browser")] public static class WebSocketProtocol { public static WebSocket CreateFromStream( diff --git a/src/libraries/System.Net.WebSockets/ref/System.Net.WebSockets.cs b/src/libraries/System.Net.WebSockets/ref/System.Net.WebSockets.cs index e4ff945..ca1e25e 100644 --- a/src/libraries/System.Net.WebSockets/ref/System.Net.WebSockets.cs +++ b/src/libraries/System.Net.WebSockets/ref/System.Net.WebSockets.cs @@ -26,8 +26,10 @@ namespace System.Net.WebSockets public abstract System.Threading.Tasks.Task CloseAsync(System.Net.WebSockets.WebSocketCloseStatus closeStatus, string? statusDescription, System.Threading.CancellationToken cancellationToken); public abstract System.Threading.Tasks.Task CloseOutputAsync(System.Net.WebSockets.WebSocketCloseStatus closeStatus, string? statusDescription, System.Threading.CancellationToken cancellationToken); public static System.ArraySegment CreateClientBuffer(int receiveBufferSize, int sendBufferSize) { throw null; } + [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] public static System.Net.WebSockets.WebSocket CreateClientWebSocket(System.IO.Stream innerStream, string? subProtocol, int receiveBufferSize, int sendBufferSize, System.TimeSpan keepAliveInterval, bool useZeroMaskingKey, System.ArraySegment internalBuffer) { throw null; } + [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] public static System.Net.WebSockets.WebSocket CreateFromStream(System.IO.Stream stream, bool isServer, string? subProtocol, System.TimeSpan keepAliveInterval) { throw null; } public static System.ArraySegment CreateServerBuffer(int receiveBufferSize) { throw null; } public abstract void Dispose(); diff --git a/src/libraries/System.Net.WebSockets/src/System/Net/WebSockets/WebSocket.cs b/src/libraries/System.Net.WebSockets/src/System/Net/WebSockets/WebSocket.cs index 3bd6835..14732fb 100644 --- a/src/libraries/System.Net.WebSockets/src/System/Net/WebSockets/WebSocket.cs +++ b/src/libraries/System.Net.WebSockets/src/System/Net/WebSockets/WebSocket.cs @@ -5,6 +5,7 @@ using System.Buffers; using System.ComponentModel; using System.IO; using System.Runtime.InteropServices; +using System.Runtime.Versioning; using System.Threading; using System.Threading.Tasks; @@ -133,6 +134,7 @@ namespace System.Net.WebSockets /// The agreed upon sub-protocol that was used when creating the connection. /// The keep-alive interval to use, or to disable keep-alives. /// The created . + [UnsupportedOSPlatform("browser")] public static WebSocket CreateFromStream(Stream stream, bool isServer, string? subProtocol, TimeSpan keepAliveInterval) { if (stream == null) @@ -172,6 +174,7 @@ namespace System.Net.WebSockets throw new PlatformNotSupportedException(); } + [UnsupportedOSPlatform("browser")] [EditorBrowsable(EditorBrowsableState.Never)] public static WebSocket CreateClientWebSocket(Stream innerStream, string? subProtocol, int receiveBufferSize, int sendBufferSize, diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/CounterGroup.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/CounterGroup.cs index effc21f..e6ce6fd 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/CounterGroup.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/CounterGroup.cs @@ -6,6 +6,7 @@ using System; using System.Diagnostics; #endif using System.Collections.Generic; +using System.Runtime.Versioning; using System.Threading; #if ES_BUILD_STANDALONE @@ -14,6 +15,7 @@ namespace Microsoft.Diagnostics.Tracing namespace System.Diagnostics.Tracing #endif { + [UnsupportedOSPlatform("browser")] internal class CounterGroup { private readonly EventSource _eventSource; diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/DiagnosticCounter.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/DiagnosticCounter.cs index c2c7e20..16724c3 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/DiagnosticCounter.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/DiagnosticCounter.cs @@ -6,6 +6,7 @@ using System; using System.Diagnostics; #endif using System.Collections.Generic; +using System.Runtime.Versioning; using System.Text; using System.Threading; @@ -19,6 +20,7 @@ namespace System.Diagnostics.Tracing /// DiagnosticCounter is an abstract class that serves as the parent class for various Counter* classes, /// namely EventCounter, PollingCounter, IncrementingEventCounter, and IncrementingPollingCounter. /// + [UnsupportedOSPlatform("browser")] public abstract class DiagnosticCounter : IDisposable { /// diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventCounter.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventCounter.cs index 9d14c88..2f4489a 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventCounter.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventCounter.cs @@ -6,6 +6,7 @@ using System; using System.Diagnostics; #endif using System.Diagnostics.CodeAnalysis; +using System.Runtime.Versioning; using System.Threading; #if ES_BUILD_STANDALONE @@ -23,6 +24,7 @@ namespace System.Diagnostics.Tracing /// See https://github.com/dotnet/runtime/blob/master/src/libraries/System.Diagnostics.Tracing/tests/BasicEventSourceTest/TestEventCounter.cs /// which shows tests, which are also useful in seeing actual use. /// + [UnsupportedOSPlatform("browser")] public partial class EventCounter : DiagnosticCounter { /// diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/IncrementingEventCounter.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/IncrementingEventCounter.cs index 8d3d378..4b4d08e 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/IncrementingEventCounter.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/IncrementingEventCounter.cs @@ -9,6 +9,8 @@ using System.Diagnostics; #if ES_BUILD_STANDALONE namespace Microsoft.Diagnostics.Tracing #else +using System.Runtime.Versioning; + namespace System.Diagnostics.Tracing #endif { @@ -18,6 +20,9 @@ namespace System.Diagnostics.Tracing /// It does not calculate statistics like mean, standard deviation, etc. because it only accumulates /// the counter value. /// +#if NETCOREAPP + [UnsupportedOSPlatform("browser")] +#endif public partial class IncrementingEventCounter : DiagnosticCounter { /// diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/IncrementingPollingCounter.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/IncrementingPollingCounter.cs index 3854d1c..d18e5ad 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/IncrementingPollingCounter.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/IncrementingPollingCounter.cs @@ -8,6 +8,8 @@ using System; #if ES_BUILD_STANDALONE namespace Microsoft.Diagnostics.Tracing #else +using System.Runtime.Versioning; + namespace System.Diagnostics.Tracing #endif { @@ -19,6 +21,9 @@ namespace System.Diagnostics.Tracing /// Unlike IncrementingEventCounter, this takes in a polling callback that it can call to update /// its own metric periodically. /// +#if NETCOREAPP + [UnsupportedOSPlatform("browser")] +#endif public partial class IncrementingPollingCounter : DiagnosticCounter { /// diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/PollingCounter.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/PollingCounter.cs index 12f0349..d2b8866 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/PollingCounter.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/PollingCounter.cs @@ -8,6 +8,8 @@ using System; #if ES_BUILD_STANDALONE namespace Microsoft.Diagnostics.Tracing #else +using System.Runtime.Versioning; + namespace System.Diagnostics.Tracing #endif { @@ -17,6 +19,9 @@ namespace System.Diagnostics.Tracing /// function to collect metrics on its own rather than the user having to call WriteMetric() /// every time. /// +#if NETCOREAPP + [UnsupportedOSPlatform("browser")] +#endif public partial class PollingCounter : DiagnosticCounter { /// diff --git a/src/libraries/System.Private.CoreLib/src/System/IO/FileStream.Unix.cs b/src/libraries/System.Private.CoreLib/src/System/IO/FileStream.Unix.cs index aa1f22a..38dc6d2 100644 --- a/src/libraries/System.Private.CoreLib/src/System/IO/FileStream.Unix.cs +++ b/src/libraries/System.Private.CoreLib/src/System/IO/FileStream.Unix.cs @@ -4,6 +4,7 @@ using Microsoft.Win32.SafeHandles; using System.Diagnostics; using System.Runtime.InteropServices; +using System.Runtime.Versioning; using System.Threading; using System.Threading.Tasks; @@ -333,7 +334,9 @@ namespace System.IO private void FlushWriteBufferForWriteByte() { +#pragma warning disable CA1416 // Validate platform compatibility, issue: https://github.com/dotnet/runtime/issues/44542 _asyncState?.Wait(); +#pragma warning restore CA1416 try { FlushWriteBuffer(); } finally { _asyncState?.Release(); } } @@ -542,7 +545,9 @@ namespace System.IO /// Reads from the file handle into the buffer, overwriting anything in it. private int FillReadBufferForReadByte() { +#pragma warning disable CA1416 // Validate platform compatibility, issue: https://github.com/dotnet/runtime/issues/44542 _asyncState?.Wait(); +#pragma warning restore CA1416 try { return ReadNative(_buffer); } finally { _asyncState?.Release(); } } diff --git a/src/libraries/System.Private.CoreLib/src/System/IO/Stream.cs b/src/libraries/System.Private.CoreLib/src/System/IO/Stream.cs index cb6f006..6a36461 100644 --- a/src/libraries/System.Private.CoreLib/src/System/IO/Stream.cs +++ b/src/libraries/System.Private.CoreLib/src/System/IO/Stream.cs @@ -218,7 +218,9 @@ namespace System.IO } else { +#pragma warning disable CA1416 // Validate platform compatibility, issue: https://github.com/dotnet/runtime/issues/44543 semaphore.Wait(); +#pragma warning restore CA1416 } // Create the task to asynchronously do a Read. This task serves both @@ -373,7 +375,9 @@ namespace System.IO } else { +#pragma warning disable CA1416 // Validate platform compatibility, issue: https://github.com/dotnet/runtime/issues/44543 semaphore.Wait(); // synchronously wait here +#pragma warning restore CA1416 } // Create the task to asynchronously do a Write. This task serves both diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/ManualResetEventSlim.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/ManualResetEventSlim.cs index 9af60a6..4f88b66 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Threading/ManualResetEventSlim.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Threading/ManualResetEventSlim.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Diagnostics; +using System.Runtime.Versioning; namespace System.Threading { @@ -357,6 +358,7 @@ namespace System.Threading /// The caller of this method blocks indefinitely until the current instance is set. The caller will /// return immediately if the event is currently in a set state. /// + [UnsupportedOSPlatform("browser")] public void Wait() { Wait(Timeout.Infinite, CancellationToken.None); @@ -377,6 +379,7 @@ namespace System.Threading /// The caller of this method blocks indefinitely until the current instance is set. The caller will /// return immediately if the event is currently in a set state. /// + [UnsupportedOSPlatform("browser")] public void Wait(CancellationToken cancellationToken) { Wait(Timeout.Infinite, cancellationToken); @@ -397,6 +400,7 @@ namespace System.Threading /// /// The maximum number of waiters has been exceeded. /// + [UnsupportedOSPlatform("browser")] public bool Wait(TimeSpan timeout) { long totalMilliseconds = (long)timeout.TotalMilliseconds; @@ -428,6 +432,7 @@ namespace System.Threading /// /// The maximum number of waiters has been exceeded. /// + [UnsupportedOSPlatform("browser")] public bool Wait(TimeSpan timeout, CancellationToken cancellationToken) { long totalMilliseconds = (long)timeout.TotalMilliseconds; @@ -452,6 +457,7 @@ namespace System.Threading /// /// The maximum number of waiters has been exceeded. /// + [UnsupportedOSPlatform("browser")] public bool Wait(int millisecondsTimeout) { return Wait(millisecondsTimeout, CancellationToken.None); @@ -475,6 +481,7 @@ namespace System.Threading /// /// was canceled. + [UnsupportedOSPlatform("browser")] public bool Wait(int millisecondsTimeout, CancellationToken cancellationToken) { ThrowIfDisposed(); diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/SemaphoreSlim.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/SemaphoreSlim.cs index 4e94381..dd57300 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Threading/SemaphoreSlim.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Threading/SemaphoreSlim.cs @@ -3,6 +3,7 @@ using System.Diagnostics; using System.Runtime.CompilerServices; +using System.Runtime.Versioning; using System.Threading.Tasks; namespace System.Threading @@ -172,6 +173,7 @@ namespace System.Threading /// /// The current instance has already been /// disposed. + [UnsupportedOSPlatform("browser")] public void Wait() { // Call wait with infinite timeout @@ -188,6 +190,7 @@ namespace System.Threading /// canceled. /// The current instance has already been /// disposed. + [UnsupportedOSPlatform("browser")] public void Wait(CancellationToken cancellationToken) { // Call wait with infinite timeout @@ -206,6 +209,7 @@ namespace System.Threading /// is a negative /// number other than -1 milliseconds, which represents an infinite time-out -or- timeout is greater /// than . + [UnsupportedOSPlatform("browser")] public bool Wait(TimeSpan timeout) { // Validate the timeout @@ -236,6 +240,7 @@ namespace System.Threading /// number other than -1 milliseconds, which represents an infinite time-out -or- timeout is greater /// than . /// was canceled. + [UnsupportedOSPlatform("browser")] public bool Wait(TimeSpan timeout, CancellationToken cancellationToken) { // Validate the timeout @@ -260,6 +265,7 @@ namespace System.Threading /// otherwise, false. /// is a /// negative number other than -1, which represents an infinite time-out. + [UnsupportedOSPlatform("browser")] public bool Wait(int millisecondsTimeout) { return Wait(millisecondsTimeout, CancellationToken.None); @@ -277,6 +283,7 @@ namespace System.Threading /// is a negative number other than -1, /// which represents an infinite time-out. /// was canceled. + [UnsupportedOSPlatform("browser")] public bool Wait(int millisecondsTimeout, CancellationToken cancellationToken) { CheckDispose(); @@ -432,6 +439,7 @@ namespace System.Threading /// The start ticks to calculate the elapsed time /// The CancellationToken to observe. /// true if the monitor received a signal, false if the timeout expired + [UnsupportedOSPlatform("browser")] private bool WaitUntilCountOrTimeout(int millisecondsTimeout, uint startTime, CancellationToken cancellationToken) { int remainingWaitMilliseconds = Timeout.Infinite; diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/FutureFactory.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/FutureFactory.cs index b2ca389..0e9090a 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/FutureFactory.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/FutureFactory.cs @@ -677,6 +677,7 @@ namespace System.Threading.Tasks } else { +#pragma warning disable CA1416 // Validate platform compatibility, issue: https://github.com/dotnet/runtime/issues/44544 ThreadPool.RegisterWaitForSingleObject( asyncResult.AsyncWaitHandle, delegate @@ -687,6 +688,7 @@ namespace System.Threading.Tasks null, Timeout.Infinite, true); +#pragma warning restore CA1416 } return promise; diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs index ac29941..7e2fb0f 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs @@ -15,6 +15,7 @@ using System.Diagnostics; using System.Diagnostics.Tracing; using System.Runtime.CompilerServices; using System.Runtime.ExceptionServices; +using System.Runtime.Versioning; using Internal.Runtime.CompilerServices; namespace System.Threading.Tasks @@ -2854,6 +2855,7 @@ namespace System.Threading.Tasks try { AddCompletionAction(mres, addBeforeOthers: true); +#pragma warning disable CA1416 // Validate platform compatibility, issue: https://github.com/dotnet/runtime/issues/44622 if (infiniteWait) { returnValue = mres.Wait(Timeout.Infinite, cancellationToken); @@ -2866,6 +2868,7 @@ namespace System.Threading.Tasks returnValue = mres.Wait((int)(millisecondsTimeout - elapsedTimeTicks), cancellationToken); } } +#pragma warning restore CA1416 } finally { @@ -4447,6 +4450,7 @@ namespace System.Threading.Tasks /// At least one of the instances was canceled -or- an exception was thrown during /// the execution of at least one of the instances. /// + [UnsupportedOSPlatform("browser")] [MethodImpl(MethodImplOptions.NoOptimization)] // this is needed for the parallel debugger public static void WaitAll(params Task[] tasks) { @@ -4489,6 +4493,7 @@ namespace System.Threading.Tasks /// infinite time-out -or- timeout is greater than /// . /// + [UnsupportedOSPlatform("browser")] [MethodImpl(MethodImplOptions.NoOptimization)] // this is needed for the parallel debugger public static bool WaitAll(Task[] tasks, TimeSpan timeout) { @@ -4527,6 +4532,7 @@ namespace System.Threading.Tasks /// is a negative number other than -1, which represents an /// infinite time-out. /// + [UnsupportedOSPlatform("browser")] [MethodImpl(MethodImplOptions.NoOptimization)] // this is needed for the parallel debugger public static bool WaitAll(Task[] tasks, int millisecondsTimeout) { @@ -4555,6 +4561,7 @@ namespace System.Threading.Tasks /// /// The was canceled. /// + [UnsupportedOSPlatform("browser")] [MethodImpl(MethodImplOptions.NoOptimization)] // this is needed for the parallel debugger public static void WaitAll(Task[] tasks, CancellationToken cancellationToken) { @@ -4595,12 +4602,14 @@ namespace System.Threading.Tasks /// /// The was canceled. /// + [UnsupportedOSPlatform("browser")] [MethodImpl(MethodImplOptions.NoOptimization)] // this is needed for the parallel debugger public static bool WaitAll(Task[] tasks, int millisecondsTimeout, CancellationToken cancellationToken) => WaitAllCore(tasks, millisecondsTimeout, cancellationToken); // Separated out to allow it to be optimized (caller is marked NoOptimization for VS parallel debugger // to be able to see the method on the stack and inspect arguments). + [UnsupportedOSPlatform("browser")] private static bool WaitAllCore(Task[] tasks, int millisecondsTimeout, CancellationToken cancellationToken) { if (tasks == null) @@ -4739,6 +4748,7 @@ namespace System.Threading.Tasks /// The timeout. /// The cancellation token. /// true if all of the tasks completed; otherwise, false. + [UnsupportedOSPlatform("browser")] private static bool WaitAllBlockingCore(List tasks, int millisecondsTimeout, CancellationToken cancellationToken) { Debug.Assert(tasks != null, "Expected a non-null list of tasks"); diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/ThreadPoolTaskScheduler.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/ThreadPoolTaskScheduler.cs index d6b85c5..dbe39bf 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/ThreadPoolTaskScheduler.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/ThreadPoolTaskScheduler.cs @@ -47,7 +47,9 @@ namespace System.Threading.Tasks // Run LongRunning tasks on their own dedicated thread. Thread thread = new Thread(s_longRunningThreadWork); thread.IsBackground = true; // Keep this thread from blocking process shutdown +#if !TARGET_BROWSER thread.Start(task); +#endif } else { diff --git a/src/libraries/System.Private.Xml/src/System/Xml/XmlDownloadManagerAsync.cs b/src/libraries/System.Private.Xml/src/System/Xml/XmlDownloadManagerAsync.cs index 87b3da7..35886f6 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/XmlDownloadManagerAsync.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/XmlDownloadManagerAsync.cs @@ -29,6 +29,7 @@ namespace System.Xml var handler = new HttpClientHandler(); using (var client = new HttpClient(handler)) { +#pragma warning disable CA1416 // Validate platform compatibility, 'credentials' and 'proxy' will not be set for browser, so safe to suppress if (credentials != null) { handler.Credentials = credentials; @@ -37,6 +38,7 @@ namespace System.Xml { handler.Proxy = proxy; } +#pragma warning restore CA1416 using (Stream respStream = await client.GetStreamAsync(uri).ConfigureAwait(false)) { diff --git a/src/libraries/System.Private.Xml/src/System/Xml/XmlUrlResolver.cs b/src/libraries/System.Private.Xml/src/System/Xml/XmlUrlResolver.cs index 641e584..3f39f1a 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/XmlUrlResolver.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/XmlUrlResolver.cs @@ -22,11 +22,13 @@ namespace System.Xml public XmlUrlResolver() { } + [UnsupportedOSPlatform("browser")] public override ICredentials? Credentials { set { _credentials = value; } } + [UnsupportedOSPlatform("browser")] public IWebProxy? Proxy { set { _proxy = value; } diff --git a/src/libraries/System.Runtime/ref/System.Runtime.cs b/src/libraries/System.Runtime/ref/System.Runtime.cs index 55d0809..e7b8eac 100644 --- a/src/libraries/System.Runtime/ref/System.Runtime.cs +++ b/src/libraries/System.Runtime/ref/System.Runtime.cs @@ -11082,10 +11082,15 @@ namespace System.Threading.Tasks public bool Wait(int millisecondsTimeout, System.Threading.CancellationToken cancellationToken) { throw null; } public void Wait(System.Threading.CancellationToken cancellationToken) { } public bool Wait(System.TimeSpan timeout) { throw null; } + [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] public static void WaitAll(params System.Threading.Tasks.Task[] tasks) { } + [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] public static bool WaitAll(System.Threading.Tasks.Task[] tasks, int millisecondsTimeout) { throw null; } + [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] public static bool WaitAll(System.Threading.Tasks.Task[] tasks, int millisecondsTimeout, System.Threading.CancellationToken cancellationToken) { throw null; } + [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] public static void WaitAll(System.Threading.Tasks.Task[] tasks, System.Threading.CancellationToken cancellationToken) { } + [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] public static bool WaitAll(System.Threading.Tasks.Task[] tasks, System.TimeSpan timeout) { throw null; } public static int WaitAny(params System.Threading.Tasks.Task[] tasks) { throw null; } public static int WaitAny(System.Threading.Tasks.Task[] tasks, int millisecondsTimeout) { throw null; } diff --git a/src/libraries/System.Security.Permissions/Directory.Build.props b/src/libraries/System.Security.Permissions/Directory.Build.props index bdcfca3..1db5968 100644 --- a/src/libraries/System.Security.Permissions/Directory.Build.props +++ b/src/libraries/System.Security.Permissions/Directory.Build.props @@ -2,5 +2,6 @@ Open + true \ No newline at end of file diff --git a/src/libraries/System.Security.Permissions/ref/System.Security.Permissions.netcoreapp.cs b/src/libraries/System.Security.Permissions/ref/System.Security.Permissions.netcoreapp.cs index 6de1351..4ed1e3e 100644 --- a/src/libraries/System.Security.Permissions/ref/System.Security.Permissions.netcoreapp.cs +++ b/src/libraries/System.Security.Permissions/ref/System.Security.Permissions.netcoreapp.cs @@ -14,6 +14,7 @@ namespace System.Xaml.Permissions public XamlLoadPermission(System.Collections.Generic.IEnumerable allowedAccess) { } public XamlLoadPermission(System.Security.Permissions.PermissionState state) { } public XamlLoadPermission(System.Xaml.Permissions.XamlAccessLevel allowedAccess) { } + [System.Runtime.Versioning.SupportedOSPlatform("windows")] public System.Collections.Generic.IList AllowedAccess { get { throw null; } } public override System.Security.IPermission Copy() { throw null; } public override bool Equals(object obj) { throw null; } diff --git a/src/libraries/System.Security.Permissions/src/System/Xaml/Permissions/XamlLoadPermission.cs b/src/libraries/System.Security.Permissions/src/System/Xaml/Permissions/XamlLoadPermission.cs index 12e7abe..cc98e5d 100644 --- a/src/libraries/System.Security.Permissions/src/System/Xaml/Permissions/XamlLoadPermission.cs +++ b/src/libraries/System.Security.Permissions/src/System/Xaml/Permissions/XamlLoadPermission.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.Collections.ObjectModel; using System.Runtime.InteropServices; +using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; @@ -21,6 +22,7 @@ namespace System.Xaml.Permissions public override bool Equals(object obj) { return ReferenceEquals(this, obj); } [ComVisible(false)] public override int GetHashCode() { return base.GetHashCode(); } + [SupportedOSPlatform("windows")] public IList AllowedAccess { get; private set; } = new ReadOnlyCollection(Array.Empty()); public override IPermission Copy() { return new XamlLoadPermission(PermissionState.Unrestricted); } public override void FromXml(SecurityElement elem) { } diff --git a/src/libraries/System.Threading.Tasks.Parallel/src/System/Threading/Tasks/Parallel.cs b/src/libraries/System.Threading.Tasks.Parallel/src/System/Threading/Tasks/Parallel.cs index 21cee18..09f40ed 100644 --- a/src/libraries/System.Threading.Tasks.Parallel/src/System/Threading/Tasks/Parallel.cs +++ b/src/libraries/System.Threading.Tasks.Parallel/src/System/Threading/Tasks/Parallel.cs @@ -346,7 +346,9 @@ namespace System.Threading.Tasks // threw an exception. We let such exceptions go completely unhandled. try { +#pragma warning disable CA1416 // Validate platform compatibility, issue: https://github.com/dotnet/runtime/issues/44605 Task.WaitAll(tasks); +#pragma warning restore CA1416 } catch (AggregateException aggExp) { diff --git a/src/libraries/System.Threading/ref/System.Threading.cs b/src/libraries/System.Threading/ref/System.Threading.cs index b60d6d0..f25070b 100644 --- a/src/libraries/System.Threading/ref/System.Threading.cs +++ b/src/libraries/System.Threading/ref/System.Threading.cs @@ -57,17 +57,25 @@ namespace System.Threading public long CurrentPhaseNumber { get { throw null; } } public int ParticipantCount { get { throw null; } } public int ParticipantsRemaining { get { throw null; } } + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public long AddParticipant() { throw null; } + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public long AddParticipants(int participantCount) { throw null; } public void Dispose() { } protected virtual void Dispose(bool disposing) { } public void RemoveParticipant() { } public void RemoveParticipants(int participantCount) { } + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public void SignalAndWait() { } + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public bool SignalAndWait(int millisecondsTimeout) { throw null; } + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public bool SignalAndWait(int millisecondsTimeout, System.Threading.CancellationToken cancellationToken) { throw null; } + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public void SignalAndWait(System.Threading.CancellationToken cancellationToken) { } + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public bool SignalAndWait(System.TimeSpan timeout) { throw null; } + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public bool SignalAndWait(System.TimeSpan timeout, System.Threading.CancellationToken cancellationToken) { throw null; } } public partial class BarrierPostPhaseException : System.Exception @@ -96,11 +104,17 @@ namespace System.Threading public bool Signal(int signalCount) { throw null; } public bool TryAddCount() { throw null; } public bool TryAddCount(int signalCount) { throw null; } + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public void Wait() { } + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public bool Wait(int millisecondsTimeout) { throw null; } + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public bool Wait(int millisecondsTimeout, System.Threading.CancellationToken cancellationToken) { throw null; } + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public void Wait(System.Threading.CancellationToken cancellationToken) { } + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public bool Wait(System.TimeSpan timeout) { throw null; } + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public bool Wait(System.TimeSpan timeout, System.Threading.CancellationToken cancellationToken) { throw null; } } public enum EventResetMode @@ -258,11 +272,17 @@ namespace System.Threading protected virtual void Dispose(bool disposing) { } public void Reset() { } public void Set() { } + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public void Wait() { } + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public bool Wait(int millisecondsTimeout) { throw null; } + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public bool Wait(int millisecondsTimeout, System.Threading.CancellationToken cancellationToken) { throw null; } + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public void Wait(System.Threading.CancellationToken cancellationToken) { } + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public bool Wait(System.TimeSpan timeout) { throw null; } + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public bool Wait(System.TimeSpan timeout, System.Threading.CancellationToken cancellationToken) { throw null; } } public static partial class Monitor @@ -307,7 +327,9 @@ namespace System.Threading public bool IsReaderLockHeld { get { throw null; } } public bool IsWriterLockHeld { get { throw null; } } public int WriterSeqNum { get { throw null; } } + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public void AcquireReaderLock(int millisecondsTimeout) { } + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public void AcquireReaderLock(System.TimeSpan timeout) { } public void AcquireWriterLock(int millisecondsTimeout) { } public void AcquireWriterLock(System.TimeSpan timeout) { } @@ -316,8 +338,11 @@ namespace System.Threading public System.Threading.LockCookie ReleaseLock() { throw null; } public void ReleaseReaderLock() { } public void ReleaseWriterLock() { } + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public void RestoreLock(ref System.Threading.LockCookie lockCookie) { } + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public System.Threading.LockCookie UpgradeToWriterLock(int millisecondsTimeout) { throw null; } + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public System.Threading.LockCookie UpgradeToWriterLock(System.TimeSpan timeout) { throw null; } } public partial class ReaderWriterLockSlim : System.IDisposable @@ -378,11 +403,17 @@ namespace System.Threading protected virtual void Dispose(bool disposing) { } public int Release() { throw null; } public int Release(int releaseCount) { throw null; } + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public void Wait() { } + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public bool Wait(int millisecondsTimeout) { throw null; } + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public bool Wait(int millisecondsTimeout, System.Threading.CancellationToken cancellationToken) { throw null; } + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public void Wait(System.Threading.CancellationToken cancellationToken) { } + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public bool Wait(System.TimeSpan timeout) { throw null; } + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public bool Wait(System.TimeSpan timeout, System.Threading.CancellationToken cancellationToken) { throw null; } public System.Threading.Tasks.Task WaitAsync() { throw null; } public System.Threading.Tasks.Task WaitAsync(int millisecondsTimeout) { throw null; } diff --git a/src/libraries/System.Threading/src/System/Threading/Barrier.cs b/src/libraries/System.Threading/src/System/Threading/Barrier.cs index 12024d6..3f5b1e9 100644 --- a/src/libraries/System.Threading/src/System/Threading/Barrier.cs +++ b/src/libraries/System.Threading/src/System/Threading/Barrier.cs @@ -12,6 +12,7 @@ using System.Diagnostics; using System.Runtime.Serialization; +using System.Runtime.Versioning; using System.Security; namespace System.Threading @@ -283,6 +284,7 @@ namespace System.Threading /// /// The current instance has already been /// disposed. + [UnsupportedOSPlatform("browser")] public long AddParticipant() { try @@ -311,6 +313,7 @@ namespace System.Threading /// /// The current instance has already been /// disposed. + [UnsupportedOSPlatform("browser")] public long AddParticipants(int participantCount) { // check dispose @@ -483,6 +486,7 @@ namespace System.Threading /// /// The current instance has already been /// disposed. + [UnsupportedOSPlatform("browser")] public void SignalAndWait() { SignalAndWait(CancellationToken.None); @@ -503,6 +507,7 @@ namespace System.Threading /// canceled. /// The current instance has already been /// disposed. + [UnsupportedOSPlatform("browser")] public void SignalAndWait(CancellationToken cancellationToken) { #if DEBUG @@ -532,6 +537,7 @@ namespace System.Threading /// /// The current instance has already been /// disposed. + [UnsupportedOSPlatform("browser")] public bool SignalAndWait(TimeSpan timeout) { return SignalAndWait(timeout, CancellationToken.None); @@ -559,6 +565,7 @@ namespace System.Threading /// canceled. /// The current instance has already been /// disposed. + [UnsupportedOSPlatform("browser")] public bool SignalAndWait(TimeSpan timeout, CancellationToken cancellationToken) { long totalMilliseconds = (long)timeout.TotalMilliseconds; @@ -586,6 +593,7 @@ namespace System.Threading /// /// The current instance has already been /// disposed. + [UnsupportedOSPlatform("browser")] public bool SignalAndWait(int millisecondsTimeout) { return SignalAndWait(millisecondsTimeout, CancellationToken.None); @@ -612,6 +620,7 @@ namespace System.Threading /// canceled. /// The current instance has already been /// disposed. + [UnsupportedOSPlatform("browser")] public bool SignalAndWait(int millisecondsTimeout, CancellationToken cancellationToken) { ThrowIfDisposed(); @@ -855,6 +864,7 @@ namespace System.Threading /// cancellation token passed to SignalAndWait /// The current phase number for this thread /// True if the event is set or the phase number changed, false if the timeout expired + [UnsupportedOSPlatform("browser")] private bool DiscontinuousWait(ManualResetEventSlim currentPhaseEvent, int totalTimeout, CancellationToken token, long observedPhase) { int maxWait = 100; // 100 ms diff --git a/src/libraries/System.Threading/src/System/Threading/CountdownEvent.cs b/src/libraries/System.Threading/src/System/Threading/CountdownEvent.cs index 7ef433c..dc3ad70 100644 --- a/src/libraries/System.Threading/src/System/Threading/CountdownEvent.cs +++ b/src/libraries/System.Threading/src/System/Threading/CountdownEvent.cs @@ -8,6 +8,7 @@ // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- using System.Diagnostics; +using System.Runtime.Versioning; namespace System.Threading { @@ -414,6 +415,7 @@ namespace System.Threading /// /// The current instance has already been /// disposed. + [UnsupportedOSPlatform("browser")] public void Wait() { Wait(Timeout.Infinite, CancellationToken.None); @@ -437,6 +439,7 @@ namespace System.Threading /// canceled. /// The current instance has already been /// disposed. + [UnsupportedOSPlatform("browser")] public void Wait(CancellationToken cancellationToken) { Wait(Timeout.Infinite, cancellationToken); @@ -456,6 +459,7 @@ namespace System.Threading /// than . /// The current instance has already been /// disposed. + [UnsupportedOSPlatform("browser")] public bool Wait(TimeSpan timeout) { long totalMilliseconds = (long)timeout.TotalMilliseconds; @@ -486,6 +490,7 @@ namespace System.Threading /// disposed. /// has /// been canceled. + [UnsupportedOSPlatform("browser")] public bool Wait(TimeSpan timeout, CancellationToken cancellationToken) { long totalMilliseconds = (long)timeout.TotalMilliseconds; @@ -509,6 +514,7 @@ namespace System.Threading /// negative number other than -1, which represents an infinite time-out. /// The current instance has already been /// disposed. + [UnsupportedOSPlatform("browser")] public bool Wait(int millisecondsTimeout) { return Wait(millisecondsTimeout, CancellationToken.None); @@ -531,6 +537,7 @@ namespace System.Threading /// disposed. /// has /// been canceled. + [UnsupportedOSPlatform("browser")] public bool Wait(int millisecondsTimeout, CancellationToken cancellationToken) { if (millisecondsTimeout < -1) diff --git a/src/libraries/System.Threading/src/System/Threading/ReaderWriterLock.cs b/src/libraries/System.Threading/src/System/Threading/ReaderWriterLock.cs index 90a8e51..1d49a2c 100644 --- a/src/libraries/System.Threading/src/System/Threading/ReaderWriterLock.cs +++ b/src/libraries/System.Threading/src/System/Threading/ReaderWriterLock.cs @@ -4,6 +4,7 @@ using System.Diagnostics; using System.Runtime.ConstrainedExecution; using System.Runtime.Serialization; +using System.Runtime.Versioning; namespace System.Threading { @@ -73,6 +74,7 @@ namespace System.Threading return (uint)_writerSeqNum > (uint)seqNum; } + [UnsupportedOSPlatform("browser")] public void AcquireReaderLock(int millisecondsTimeout) { if (millisecondsTimeout < -1) @@ -275,6 +277,7 @@ namespace System.Threading ++threadLocalLockEntry._readerLevel; } + [UnsupportedOSPlatform("browser")] public void AcquireReaderLock(TimeSpan timeout) => AcquireReaderLock(ToTimeoutMilliseconds(timeout)); public void AcquireWriterLock(int millisecondsTimeout) @@ -665,6 +668,7 @@ namespace System.Threading } } + [UnsupportedOSPlatform("browser")] public LockCookie UpgradeToWriterLock(int millisecondsTimeout) { if (millisecondsTimeout < -1) @@ -744,6 +748,7 @@ namespace System.Threading } } + [UnsupportedOSPlatform("browser")] public LockCookie UpgradeToWriterLock(TimeSpan timeout) => UpgradeToWriterLock(ToTimeoutMilliseconds(timeout)); public void DowngradeFromWriterLock(ref LockCookie lockCookie) @@ -911,6 +916,7 @@ namespace System.Threading return lockCookie; } + [UnsupportedOSPlatform("browser")] public void RestoreLock(ref LockCookie lockCookie) { // Validate cookie @@ -976,6 +982,7 @@ namespace System.Threading /// /// Helper function that restores the lock to the original state indicated by parameters /// + [UnsupportedOSPlatform("browser")] private void RecoverLock(ref LockCookie lockCookie, LockCookieFlags flags) { // Contrary to the legacy code, this method does not use a finite timeout for recovering the previous lock state, as diff --git a/src/libraries/System.Transactions.Local/ref/System.Transactions.Local.cs b/src/libraries/System.Transactions.Local/ref/System.Transactions.Local.cs index d6c0a60..9520218 100644 --- a/src/libraries/System.Transactions.Local/ref/System.Transactions.Local.cs +++ b/src/libraries/System.Transactions.Local/ref/System.Transactions.Local.cs @@ -6,6 +6,7 @@ namespace System.Transactions { + [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] public sealed partial class CommittableTransaction : System.Transactions.Transaction, System.IAsyncResult { public CommittableTransaction() { } @@ -218,6 +219,7 @@ namespace System.Transactions public TransactionPromotionException(string? message) { } public TransactionPromotionException(string? message, System.Exception? innerException) { } } + [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] public sealed partial class TransactionScope : System.IDisposable { public TransactionScope() { } diff --git a/src/libraries/System.Transactions.Local/src/System/Transactions/CommittableTransaction.cs b/src/libraries/System.Transactions.Local/src/System/Transactions/CommittableTransaction.cs index 1388352..e387159 100644 --- a/src/libraries/System.Transactions.Local/src/System/Transactions/CommittableTransaction.cs +++ b/src/libraries/System.Transactions.Local/src/System/Transactions/CommittableTransaction.cs @@ -2,10 +2,12 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Diagnostics; +using System.Runtime.Versioning; using System.Threading; namespace System.Transactions { + [UnsupportedOSPlatform("browser")] public sealed class CommittableTransaction : Transaction, IAsyncResult { // Create a transaction with defaults diff --git a/src/libraries/System.Transactions.Local/src/System/Transactions/Transaction.cs b/src/libraries/System.Transactions.Local/src/System/Transactions/Transaction.cs index 2cc0efd..3851ed0 100644 --- a/src/libraries/System.Transactions.Local/src/System/Transactions/Transaction.cs +++ b/src/libraries/System.Transactions.Local/src/System/Transactions/Transaction.cs @@ -70,7 +70,9 @@ namespace System.Transactions { if (currentScope != null) { +#pragma warning disable CA1416 // Validate platform compatibility, the property is not platform-specific, safe to suppress return currentScope.InteropMode; +#pragma warning restore CA1416 } return EnterpriseServicesInteropOption.None; @@ -161,7 +163,9 @@ namespace System.Transactions if (currentScope != null) { +#pragma warning disable CA1416 // Validate platform compatibility, the property is not platform-specific, safe to suppress if (currentScope.ScopeComplete) +#pragma warning restore CA1416 { throw new InvalidOperationException(SR.TransactionScopeComplete); } diff --git a/src/libraries/System.Transactions.Local/src/System/Transactions/TransactionScope.cs b/src/libraries/System.Transactions.Local/src/System/Transactions/TransactionScope.cs index 3a991ca..a022034 100644 --- a/src/libraries/System.Transactions.Local/src/System/Transactions/TransactionScope.cs +++ b/src/libraries/System.Transactions.Local/src/System/Transactions/TransactionScope.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Diagnostics; +using System.Runtime.Versioning; using System.Threading; namespace System.Transactions @@ -32,6 +33,7 @@ namespace System.Transactions Full = 2 } + [UnsupportedOSPlatform("browser")] public sealed class TransactionScope : IDisposable { public TransactionScope() : this(TransactionScopeOption.Required) diff --git a/src/libraries/System.Xml.ReaderWriter/ref/System.Xml.ReaderWriter.cs b/src/libraries/System.Xml.ReaderWriter/ref/System.Xml.ReaderWriter.cs index ef1f8e2..ddbf60b 100644 --- a/src/libraries/System.Xml.ReaderWriter/ref/System.Xml.ReaderWriter.cs +++ b/src/libraries/System.Xml.ReaderWriter/ref/System.Xml.ReaderWriter.cs @@ -1138,7 +1138,9 @@ namespace System.Xml { public XmlUrlResolver() { } public System.Net.Cache.RequestCachePolicy CachePolicy { set { } } + [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] public override System.Net.ICredentials? Credentials { set { } } + [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] public System.Net.IWebProxy? Proxy { set { } } public override object? GetEntity(System.Uri absoluteUri, string? role, System.Type? ofObjectToReturn) { throw null; } public override System.Threading.Tasks.Task GetEntityAsync(System.Uri absoluteUri, string? role, System.Type? ofObjectToReturn) { throw null; } diff --git a/src/mono/netcore/System.Private.CoreLib/System.Private.CoreLib.csproj b/src/mono/netcore/System.Private.CoreLib/System.Private.CoreLib.csproj index e123641..6a40f5f 100644 --- a/src/mono/netcore/System.Private.CoreLib/System.Private.CoreLib.csproj +++ b/src/mono/netcore/System.Private.CoreLib/System.Private.CoreLib.csproj @@ -1,4 +1,4 @@ - + @@ -293,6 +293,11 @@ + + + + + -- 2.7.4