Handle unsupported browser warnings (#43363)
authorBuyaa <bunamnan@microsoft.com>
Wed, 25 Nov 2020 21:20:52 +0000 (13:20 -0800)
committerGitHub <noreply@github.com>
Wed, 25 Nov 2020 21:20:52 +0000 (21:20 +0000)
* 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

64 files changed:
eng/versioning.targets
src/libraries/Common/src/System/Net/WebSockets/ManagedWebSocket.cs
src/libraries/Microsoft.Extensions.Logging.Console/ref/Microsoft.Extensions.Logging.Console.cs
src/libraries/Microsoft.Extensions.Logging.Console/ref/Microsoft.Extensions.Logging.Console.csproj
src/libraries/Microsoft.Extensions.Logging.Console/src/AnsiParsingLogConsole.cs
src/libraries/Microsoft.Extensions.Logging.Console/src/ConsoleLogger.cs
src/libraries/Microsoft.Extensions.Logging.Console/src/ConsoleLoggerExtensions.cs
src/libraries/Microsoft.Extensions.Logging.Console/src/ConsoleLoggerProcessor.cs
src/libraries/Microsoft.Extensions.Logging.Console/src/ConsoleLoggerProvider.cs
src/libraries/Microsoft.Extensions.Logging.Console/src/Microsoft.Extensions.Logging.Console.csproj
src/libraries/System.Collections.Concurrent/ref/System.Collections.Concurrent.cs
src/libraries/System.Collections.Concurrent/src/System/Collections/Concurrent/BlockingCollection.cs
src/libraries/System.ComponentModel.TypeConverter/ref/System.ComponentModel.TypeConverter.cs
src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/TypeDescriptionProvider.cs
src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/TypeDescriptor.cs
src/libraries/System.Diagnostics.TextWriterTraceListener/src/System/Diagnostics/XmlWriterTraceListener.cs
src/libraries/System.Diagnostics.Tracing/ref/System.Diagnostics.Tracing.Counters.cs
src/libraries/System.Linq.Parallel/Directory.Build.props
src/libraries/System.Net.Connections/Directory.Build.props
src/libraries/System.Net.Http/ref/System.Net.Http.cs
src/libraries/System.Net.Http/src/System.Net.Http.csproj
src/libraries/System.Net.Http/src/System/Net/Http/BrowserHttpHandler/HttpTelemetry.Browser.cs [new file with mode: 0644]
src/libraries/System.Net.Http/src/System/Net/Http/HttpClient.cs
src/libraries/System.Net.Http/src/System/Net/Http/HttpClientHandler.cs
src/libraries/System.Net.Http/src/System/Net/Http/HttpTelemetry.AnyOS.cs [new file with mode: 0644]
src/libraries/System.Net.Http/src/System/Net/Http/HttpTelemetry.cs
src/libraries/System.Net.ServicePoint/ref/System.Net.ServicePoint.cs
src/libraries/System.Net.ServicePoint/src/System/Net/ServicePointManager.cs
src/libraries/System.Net.WebProxy/src/System/Net/WebProxy.cs
src/libraries/System.Net.WebSockets.WebSocketProtocol/Directory.Build.props
src/libraries/System.Net.WebSockets.WebSocketProtocol/ref/System.Net.WebSockets.WebSocketProtocol.cs
src/libraries/System.Net.WebSockets.WebSocketProtocol/src/System/Net/WebSockets/WebSocketProtocol.cs
src/libraries/System.Net.WebSockets/ref/System.Net.WebSockets.cs
src/libraries/System.Net.WebSockets/src/System/Net/WebSockets/WebSocket.cs
src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/CounterGroup.cs
src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/DiagnosticCounter.cs
src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventCounter.cs
src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/IncrementingEventCounter.cs
src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/IncrementingPollingCounter.cs
src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/PollingCounter.cs
src/libraries/System.Private.CoreLib/src/System/IO/FileStream.Unix.cs
src/libraries/System.Private.CoreLib/src/System/IO/Stream.cs
src/libraries/System.Private.CoreLib/src/System/Threading/ManualResetEventSlim.cs
src/libraries/System.Private.CoreLib/src/System/Threading/SemaphoreSlim.cs
src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/FutureFactory.cs
src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs
src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/ThreadPoolTaskScheduler.cs
src/libraries/System.Private.Xml/src/System/Xml/XmlDownloadManagerAsync.cs
src/libraries/System.Private.Xml/src/System/Xml/XmlUrlResolver.cs
src/libraries/System.Runtime/ref/System.Runtime.cs
src/libraries/System.Security.Permissions/Directory.Build.props
src/libraries/System.Security.Permissions/ref/System.Security.Permissions.netcoreapp.cs
src/libraries/System.Security.Permissions/src/System/Xaml/Permissions/XamlLoadPermission.cs
src/libraries/System.Threading.Tasks.Parallel/src/System/Threading/Tasks/Parallel.cs
src/libraries/System.Threading/ref/System.Threading.cs
src/libraries/System.Threading/src/System/Threading/Barrier.cs
src/libraries/System.Threading/src/System/Threading/CountdownEvent.cs
src/libraries/System.Threading/src/System/Threading/ReaderWriterLock.cs
src/libraries/System.Transactions.Local/ref/System.Transactions.Local.cs
src/libraries/System.Transactions.Local/src/System/Transactions/CommittableTransaction.cs
src/libraries/System.Transactions.Local/src/System/Transactions/Transaction.cs
src/libraries/System.Transactions.Local/src/System/Transactions/TransactionScope.cs
src/libraries/System.Xml.ReaderWriter/ref/System.Xml.ReaderWriter.cs
src/mono/netcore/System.Private.CoreLib/System.Private.CoreLib.csproj

index 3177b48..98fd08c 100644 (file)
     </AssemblyAttribute>
   </ItemGroup>
 
+  <PropertyGroup Condition="'$(TargetsAnyOS)' == 'true' and !$(TargetFrameworks.Contains('$(TargetFramework)-Browser'))">
+      <CrossPlatformAndHasNoBrowserTarget>true</CrossPlatformAndHasNoBrowserTarget>
+  </PropertyGroup>
+  
+  <!-- Enables browser warnings for cross platform or Brwoser targeted builds -->
+  <ItemGroup Condition="('$(TargetsBrowser)' == 'true' or '$(CrossPlatformAndHasNoBrowserTarget)' == 'true') and '$(IsTestProject)' != 'true'">
+    <SupportedPlatform Include="browser"/>
+  </ItemGroup>
+
   <ItemGroup>
     <_unsupportedOSPlatforms Include="$(UnsupportedOSPlatforms)" />
   </ItemGroup>
index 7ed7a15..cffafdd 100644 (file)
@@ -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.
     /// </remarks>
+    [UnsupportedOSPlatform("browser")]
     internal sealed partial class ManagedWebSocket : WebSocket
     {
         /// <summary>Creates a <see cref="ManagedWebSocket"/> from a <see cref="Stream"/> connected to a websocket endpoint.</summary>
index 80e365a..4cca93a 100644 (file)
@@ -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
     {
index 048eb04..41c181e 100644 (file)
@@ -1,6 +1,7 @@
 <Project Sdk="Microsoft.NET.Sdk">
   <PropertyGroup>
     <TargetFrameworks>netstandard2.0;net461</TargetFrameworks>
+    <IncludePlatformAttributes>true</IncludePlatformAttributes>
   </PropertyGroup>
 
   <ItemGroup>
index 9f42ec6..6a44732 100644 (file)
@@ -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;
index 1d544f3..daa903d 100644 (file)
@@ -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;
index 8cd8a59..9d12ac5 100644 (file)
@@ -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
     {
         /// <summary>
@@ -154,6 +156,7 @@ namespace Microsoft.Extensions.Logging
         }
     }
 
+    [UnsupportedOSPlatform("browser")]
     internal class ConsoleLoggerFormatterConfigureOptions<TFormatter, TOptions> : ConfigureFromConfigurationOptions<TOptions>
         where TOptions : ConsoleFormatterOptions
         where TFormatter : ConsoleFormatter
@@ -164,6 +167,7 @@ namespace Microsoft.Extensions.Logging
         }
     }
 
+    [UnsupportedOSPlatform("browser")]
     internal class ConsoleLoggerFormatterOptionsChangeTokenSource<TFormatter, TOptions> : ConfigurationChangeTokenSource<TOptions>
         where TOptions : ConsoleFormatterOptions
         where TFormatter : ConsoleFormatter
index 83a49c2..c79ccac 100644 (file)
@@ -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;
index 7a8f613..fd995f7 100644 (file)
@@ -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
     /// <summary>
     /// A provider of <see cref="ConsoleLogger"/> instances.
     /// </summary>
+    [UnsupportedOSPlatform("browser")]
     [ProviderAlias("Console")]
     public class ConsoleLoggerProvider : ILoggerProvider, ISupportExternalScope
     {
index 1e8e0f4..ef573cd 100644 (file)
@@ -1,4 +1,4 @@
-<Project Sdk="Microsoft.NET.Sdk">
+<Project Sdk="Microsoft.NET.Sdk">
 
   <PropertyGroup>
     <TargetFrameworks>$(NetCoreAppCurrent);netcoreapp3.0;netstandard2.0;net461</TargetFrameworks>
@@ -8,6 +8,7 @@
     <DefineConstants>$(DefineConstants);NO_SUPPRESS_GC_TRANSITION</DefineConstants>
     <!-- Use targeting pack references instead of granular ones in the project file. -->
     <DisableImplicitAssemblyReferences>false</DisableImplicitAssemblyReferences>
+    <IncludePlatformAttributes>true</IncludePlatformAttributes>
   </PropertyGroup>
 
   <ItemGroup>
index c1a477b..a7955b0 100644 (file)
@@ -6,6 +6,7 @@
 
 namespace System.Collections.Concurrent
 {
+    [System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
     public partial class BlockingCollection<T> : System.Collections.Generic.IEnumerable<T>, System.Collections.Generic.IReadOnlyCollection<T>, System.Collections.ICollection, System.Collections.IEnumerable, System.IDisposable
     {
         public BlockingCollection() { }
index 40dc971..3640d0d 100644 (file)
@@ -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 <see cref="System.Collections.Concurrent.IProducerConsumerCollection{T}"/>.
     /// </remarks>
     /// <typeparam name="T">Specifies the type of elements in the collection.</typeparam>
+    [UnsupportedOSPlatform("browser")]
     [DebuggerTypeProxy(typeof(BlockingCollectionDebugView<>))]
     [DebuggerDisplay("Count = {Count}, Type = {_collection}")]
     public class BlockingCollection<T> : IEnumerable<T>, ICollection, IDisposable, IReadOnlyCollection<T>
@@ -1801,6 +1803,7 @@ namespace System.Collections.Concurrent
         }
 
         /// <summary>Returns a snapshot of the underlying collection's elements.</summary>
+        [UnsupportedOSPlatform("browser")]
         [DebuggerBrowsable(DebuggerBrowsableState.RootHidden)]
         public T[] Items
         {
index ff1082f..d741db0 100644 (file)
@@ -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; }
index 565bc42..28b7a3a 100644 (file)
@@ -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.
         /// </summary>
-        [UnsupportedOSPlatform("browser")]
         public virtual object CreateInstance(IServiceProvider provider, Type objectType, Type[] argTypes, object[] args)
         {
             if (_parent != null)
index a542eb2..0dc2b32 100644 (file)
@@ -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.
         /// </summary>
-        [UnsupportedOSPlatform("browser")]
         public static object CreateInstance(IServiceProvider provider, Type objectType, Type[] argTypes, object[] args)
         {
             if (objectType == null)
index bf97f5f..798968d 100644 (file)
@@ -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;
                 }
             }
 
index 2e1cce9..56c748f 100644 (file)
@@ -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<double> 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<double> 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) { }
index e8d6554..7c0e0c2 100644 (file)
@@ -2,5 +2,6 @@
   <Import Project="..\Directory.Build.props" />
   <PropertyGroup>
     <StrongNameKeyId>Microsoft</StrongNameKeyId>
+    <UnsupportedOSPlatforms>browser</UnsupportedOSPlatforms>
   </PropertyGroup>
 </Project>
index 63f02a0..0a5c846 100644 (file)
@@ -2,5 +2,6 @@
   <Import Project="..\Directory.Build.props" />
   <PropertyGroup>
     <StrongNameKeyId>Microsoft</StrongNameKeyId>
+    <UnsupportedOSPlatforms>browser</UnsupportedOSPlatforms>
   </PropertyGroup>
 </Project>
\ No newline at end of file
index 35406af..d38fc45 100644 (file)
@@ -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<System.Net.Http.HttpRequestMessage, System.Security.Cryptography.X509Certificates.X509Certificate2?, System.Security.Cryptography.X509Certificates.X509Chain?, System.Net.Security.SslPolicyErrors, bool> DangerousAcceptAnyServerCertificateValidator { get { throw null; } }
         [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
         public System.Net.ICredentials? DefaultProxyCredentials { get { throw null; } set { } }
index 70c8da7..13f7c27 100644 (file)
@@ -1,4 +1,4 @@
-<Project Sdk="Microsoft.NET.Sdk">
+<Project Sdk="Microsoft.NET.Sdk">
   <PropertyGroup>
     <WindowsRID>win</WindowsRID>
     <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
     <Compile Include="System\Net\Http\Headers\UriHeaderParser.cs" />
     <Compile Include="System\Net\Http\Headers\ViaHeaderValue.cs" />
     <Compile Include="System\Net\Http\Headers\WarningHeaderValue.cs" />
-    <Compile Include="$(CommonPath)System\Net\Security\SslClientAuthenticationOptionsExtensions.cs"
-             Link="Common\System\Net\Security\SslClientAuthenticationOptionsExtensions.cs" />
     <Compile Include="$(CommonPath)System\IO\DelegatingStream.cs"
              Link="Common\System\IO\DelegatingStream.cs" />
     <Compile Include="$(CommonPath)System\IO\ReadOnlyMemoryStream.cs"
     <Compile Include="System\Net\Http\SocketsHttpHandler\RedirectHandler.cs" />
     <Compile Include="System\Net\Http\SocketsHttpHandler\SocketsHttpConnectionContext.cs" />
     <Compile Include="System\Net\Http\SocketsHttpHandler\SocketsHttpHandler.cs" />
+    <Compile Include="System\Net\Http\HttpTelemetry.AnyOS.cs" />
     <Compile Include="System\Net\Http\HttpUtilities.AnyOS.cs" />
     <Compile Include="System\Net\Http\SocketsHttpHandler\SystemProxyInfo.cs" />
     <Compile Include="$(CommonPath)System\Net\NTAuthentication.Common.cs"
              Link="Common\System\Net\SecurityStatusPal.cs" />
     <Compile Include="$(CommonPath)System\Net\Security\SSPIHandleCache.cs"
              Link="Common\System\Net\Security\SSPIHandleCache.cs" />
+    <Compile Include="$(CommonPath)System\Net\Security\SslClientAuthenticationOptionsExtensions.cs"
+             Link="Common\System\Net\Security\SslClientAuthenticationOptionsExtensions.cs" />
     <Compile Include="$(CommonPath)System\Net\Security\NetEventSource.Security.cs"
              Link="Common\System\Net\Security\NetEventSource.Security.cs" />
     <Compile Include="$(CommonPath)System\Net\ExceptionCheck.cs"
     <Compile Include="System\Net\Http\BrowserHttpHandler\SystemProxyInfo.Browser.cs" />
     <Compile Include="System\Net\Http\BrowserHttpHandler\SocketsHttpHandler.cs" />
     <Compile Include="System\Net\Http\BrowserHttpHandler\BrowserHttpHandler.cs" />
+    <Compile Include="System\Net\Http\BrowserHttpHandler\HttpTelemetry.Browser.cs" />
     <Compile Include="System\Net\Http\BrowserHttpHandler\HttpUtilities.Browser.cs" />
     <Compile Include="$(CommonPath)System\Net\Http\HttpHandlerDefaults.cs"
              Link="Common\System\Net\Http\HttpHandlerDefaults.cs" />
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 (file)
index 0000000..406afd1
--- /dev/null
@@ -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)
+        {
+        }
+    }
+}
index 807bab6..5b81865 100644 (file)
@@ -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.
index 81de5ba..2e32896 100644 (file)
@@ -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<HttpRequestMessage, X509Certificate2?, X509Chain?, SslPolicyErrors, bool>? s_dangerousAcceptAnyServerCertificateValidator;
+        [UnsupportedOSPlatform("browser")]
         public static Func<HttpRequestMessage, X509Certificate2?, X509Chain?, SslPolicyErrors, bool> 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 (file)
index 0000000..0a7e908
--- /dev/null
@@ -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"
+                };
+            }
+        }
+    }
+}
index 5879581..385d959 100644 (file)
@@ -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())
index d7adfc5..f26d234 100644 (file)
@@ -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 { } }
index 267610d..eb27864 100644 (file)
@@ -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)]
index b853be8..a5db1a0 100644 (file)
@@ -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
index bdcfca3..1db5968 100644 (file)
@@ -2,5 +2,6 @@
   <Import Project="..\Directory.Build.props" />
   <PropertyGroup>
     <StrongNameKeyId>Open</StrongNameKeyId>
+    <IncludePlatformAttributes>true</IncludePlatformAttributes>
   </PropertyGroup>
 </Project>
\ No newline at end of file
index 7b6113f..295705f 100644 (file)
@@ -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; }
index 49e3196..1178e70 100644 (file)
@@ -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(
index e4ff945..ca1e25e 100644 (file)
@@ -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<byte> 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<byte> 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<byte> CreateServerBuffer(int receiveBufferSize) { throw null; }
         public abstract void Dispose();
index 3bd6835..14732fb 100644 (file)
@@ -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
         /// <param name="subProtocol">The agreed upon sub-protocol that was used when creating the connection.</param>
         /// <param name="keepAliveInterval">The keep-alive interval to use, or <see cref="Timeout.InfiniteTimeSpan"/> to disable keep-alives.</param>
         /// <returns>The created <see cref="WebSocket"/>.</returns>
+        [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,
index effc21f..e6ce6fd 100644 (file)
@@ -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;
index c2c7e20..16724c3 100644 (file)
@@ -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.
     /// </summary>
+    [UnsupportedOSPlatform("browser")]
     public abstract class DiagnosticCounter : IDisposable
     {
         /// <summary>
index 9d14c88..2f4489a 100644 (file)
@@ -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.
     /// </summary>
+    [UnsupportedOSPlatform("browser")]
     public partial class EventCounter : DiagnosticCounter
     {
         /// <summary>
index 8d3d378..4b4d08e 100644 (file)
@@ -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.
     /// </summary>
+#if NETCOREAPP
+    [UnsupportedOSPlatform("browser")]
+#endif
     public partial class IncrementingEventCounter : DiagnosticCounter
     {
         /// <summary>
index 3854d1c..d18e5ad 100644 (file)
@@ -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.
     /// </summary>
+#if NETCOREAPP
+    [UnsupportedOSPlatform("browser")]
+#endif
     public partial class IncrementingPollingCounter : DiagnosticCounter
     {
         /// <summary>
index 12f0349..d2b8866 100644 (file)
@@ -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.
     /// </summary>
+#if NETCOREAPP
+    [UnsupportedOSPlatform("browser")]
+#endif
     public partial class PollingCounter : DiagnosticCounter
     {
         /// <summary>
index aa1f22a..38dc6d2 100644 (file)
@@ -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
         /// <summary>Reads from the file handle into the buffer, overwriting anything in it.</summary>
         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(); }
         }
index cb6f006..6a36461 100644 (file)
@@ -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
index 9af60a6..4f88b66 100644 (file)
@@ -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.
         /// </remarks>
+        [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.
         /// </remarks>
+        [UnsupportedOSPlatform("browser")]
         public void Wait(CancellationToken cancellationToken)
         {
             Wait(Timeout.Infinite, cancellationToken);
@@ -397,6 +400,7 @@ namespace System.Threading
         /// <exception cref="System.InvalidOperationException">
         /// The maximum number of waiters has been exceeded.
         /// </exception>
+        [UnsupportedOSPlatform("browser")]
         public bool Wait(TimeSpan timeout)
         {
             long totalMilliseconds = (long)timeout.TotalMilliseconds;
@@ -428,6 +432,7 @@ namespace System.Threading
         /// <exception cref="System.InvalidOperationException">
         /// The maximum number of waiters has been exceeded.
         /// </exception>
+        [UnsupportedOSPlatform("browser")]
         public bool Wait(TimeSpan timeout, CancellationToken cancellationToken)
         {
             long totalMilliseconds = (long)timeout.TotalMilliseconds;
@@ -452,6 +457,7 @@ namespace System.Threading
         /// <exception cref="System.InvalidOperationException">
         /// The maximum number of waiters has been exceeded.
         /// </exception>
+        [UnsupportedOSPlatform("browser")]
         public bool Wait(int millisecondsTimeout)
         {
             return Wait(millisecondsTimeout, CancellationToken.None);
@@ -475,6 +481,7 @@ namespace System.Threading
         /// </exception>
         /// <exception cref="System.OperationCanceledException"><paramref
         /// name="cancellationToken"/> was canceled.</exception>
+        [UnsupportedOSPlatform("browser")]
         public bool Wait(int millisecondsTimeout, CancellationToken cancellationToken)
         {
             ThrowIfDisposed();
index 4e94381..dd57300 100644 (file)
@@ -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
         /// </summary>
         /// <exception cref="System.ObjectDisposedException">The current instance has already been
         /// disposed.</exception>
+        [UnsupportedOSPlatform("browser")]
         public void Wait()
         {
             // Call wait with infinite timeout
@@ -188,6 +190,7 @@ namespace System.Threading
         /// canceled.</exception>
         /// <exception cref="System.ObjectDisposedException">The current instance has already been
         /// disposed.</exception>
+        [UnsupportedOSPlatform("browser")]
         public void Wait(CancellationToken cancellationToken)
         {
             // Call wait with infinite timeout
@@ -206,6 +209,7 @@ namespace System.Threading
         /// <exception cref="System.ArgumentOutOfRangeException"><paramref name="timeout"/> is a negative
         /// number other than -1 milliseconds, which represents an infinite time-out -or- timeout is greater
         /// than <see cref="int.MaxValue"/>.</exception>
+        [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 <see cref="int.MaxValue"/>.</exception>
         /// <exception cref="System.OperationCanceledException"><paramref name="cancellationToken"/> was canceled.</exception>
+        [UnsupportedOSPlatform("browser")]
         public bool Wait(TimeSpan timeout, CancellationToken cancellationToken)
         {
             // Validate the timeout
@@ -260,6 +265,7 @@ namespace System.Threading
         /// otherwise, false.</returns>
         /// <exception cref="ArgumentOutOfRangeException"><paramref name="millisecondsTimeout"/> is a
         /// negative number other than -1, which represents an infinite time-out.</exception>
+        [UnsupportedOSPlatform("browser")]
         public bool Wait(int millisecondsTimeout)
         {
             return Wait(millisecondsTimeout, CancellationToken.None);
@@ -277,6 +283,7 @@ namespace System.Threading
         /// <exception cref="ArgumentOutOfRangeException"><paramref name="millisecondsTimeout"/> is a negative number other than -1,
         /// which represents an infinite time-out.</exception>
         /// <exception cref="System.OperationCanceledException"><paramref name="cancellationToken"/> was canceled.</exception>
+        [UnsupportedOSPlatform("browser")]
         public bool Wait(int millisecondsTimeout, CancellationToken cancellationToken)
         {
             CheckDispose();
@@ -432,6 +439,7 @@ namespace System.Threading
         /// <param name="startTime">The start ticks to calculate the elapsed time</param>
         /// <param name="cancellationToken">The CancellationToken to observe.</param>
         /// <returns>true if the monitor received a signal, false if the timeout expired</returns>
+        [UnsupportedOSPlatform("browser")]
         private bool WaitUntilCountOrTimeout(int millisecondsTimeout, uint startTime, CancellationToken cancellationToken)
         {
             int remainingWaitMilliseconds = Timeout.Infinite;
index b2ca389..0e9090a 100644 (file)
@@ -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;
index ac29941..7e2fb0f 100644 (file)
@@ -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 <see cref="Task"/> instances was canceled -or- an exception was thrown during
         /// the execution of at least one of the <see cref="Task"/> instances.
         /// </exception>
+        [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
         /// <see cref="int.MaxValue"/>.
         /// </exception>
+        [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
         /// <paramref name="millisecondsTimeout"/> is a negative number other than -1, which represents an
         /// infinite time-out.
         /// </exception>
+        [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
         /// <exception cref="System.OperationCanceledException">
         /// The <paramref name="cancellationToken"/> was canceled.
         /// </exception>
+        [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
         /// <exception cref="System.OperationCanceledException">
         /// The <paramref name="cancellationToken"/> was canceled.
         /// </exception>
+        [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
         /// <param name="millisecondsTimeout">The timeout.</param>
         /// <param name="cancellationToken">The cancellation token.</param>
         /// <returns>true if all of the tasks completed; otherwise, false.</returns>
+        [UnsupportedOSPlatform("browser")]
         private static bool WaitAllBlockingCore(List<Task> tasks, int millisecondsTimeout, CancellationToken cancellationToken)
         {
             Debug.Assert(tasks != null, "Expected a non-null list of tasks");
index d6b85c5..dbe39bf 100644 (file)
@@ -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
             {
index 87b3da7..35886f6 100644 (file)
@@ -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))
                 {
index 641e584..3f39f1a 100644 (file)
@@ -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; }
index 55d0809..e7b8eac 100644 (file)
@@ -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; }
index bdcfca3..1db5968 100644 (file)
@@ -2,5 +2,6 @@
   <Import Project="..\Directory.Build.props" />
   <PropertyGroup>
     <StrongNameKeyId>Open</StrongNameKeyId>
+    <IncludePlatformAttributes>true</IncludePlatformAttributes>
   </PropertyGroup>
 </Project>
\ No newline at end of file
index 6de1351..4ed1e3e 100644 (file)
@@ -14,6 +14,7 @@ namespace System.Xaml.Permissions
         public XamlLoadPermission(System.Collections.Generic.IEnumerable<System.Xaml.Permissions.XamlAccessLevel> 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<System.Xaml.Permissions.XamlAccessLevel> AllowedAccess { get { throw null; } }
         public override System.Security.IPermission Copy() { throw null; }
         public override bool Equals(object obj) { throw null; }
index 12e7abe..cc98e5d 100644 (file)
@@ -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<XamlAccessLevel> AllowedAccess { get; private set; } = new ReadOnlyCollection<XamlAccessLevel>(Array.Empty<XamlAccessLevel>());
         public override IPermission Copy() { return new XamlLoadPermission(PermissionState.Unrestricted); }
         public override void FromXml(SecurityElement elem) { }
index 21cee18..09f40ed 100644 (file)
@@ -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)
                     {
index b60d6d0..f25070b 100644 (file)
@@ -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<bool> WaitAsync(int millisecondsTimeout) { throw null; }
index 12024d6..3f5b1e9 100644 (file)
@@ -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
         /// </exception>
         /// <exception cref="System.ObjectDisposedException">The current instance has already been
         /// disposed.</exception>
+        [UnsupportedOSPlatform("browser")]
         public long AddParticipant()
         {
             try
@@ -311,6 +313,7 @@ namespace System.Threading
         /// </exception>
         /// <exception cref="System.ObjectDisposedException">The current instance has already been
         /// disposed.</exception>
+        [UnsupportedOSPlatform("browser")]
         public long AddParticipants(int participantCount)
         {
             // check dispose
@@ -483,6 +486,7 @@ namespace System.Threading
         /// </exception>
         /// <exception cref="System.ObjectDisposedException">The current instance has already been
         /// disposed.</exception>
+        [UnsupportedOSPlatform("browser")]
         public void SignalAndWait()
         {
             SignalAndWait(CancellationToken.None);
@@ -503,6 +507,7 @@ namespace System.Threading
         /// canceled.</exception>
         /// <exception cref="System.ObjectDisposedException">The current instance has already been
         /// disposed.</exception>
+        [UnsupportedOSPlatform("browser")]
         public void SignalAndWait(CancellationToken cancellationToken)
         {
 #if DEBUG
@@ -532,6 +537,7 @@ namespace System.Threading
         /// </exception>
         /// <exception cref="System.ObjectDisposedException">The current instance has already been
         /// disposed.</exception>
+        [UnsupportedOSPlatform("browser")]
         public bool SignalAndWait(TimeSpan timeout)
         {
             return SignalAndWait(timeout, CancellationToken.None);
@@ -559,6 +565,7 @@ namespace System.Threading
         /// canceled.</exception>
         /// <exception cref="System.ObjectDisposedException">The current instance has already been
         /// disposed.</exception>
+        [UnsupportedOSPlatform("browser")]
         public bool SignalAndWait(TimeSpan timeout, CancellationToken cancellationToken)
         {
             long totalMilliseconds = (long)timeout.TotalMilliseconds;
@@ -586,6 +593,7 @@ namespace System.Threading
         /// </exception>
         /// <exception cref="System.ObjectDisposedException">The current instance has already been
         /// disposed.</exception>
+        [UnsupportedOSPlatform("browser")]
         public bool SignalAndWait(int millisecondsTimeout)
         {
             return SignalAndWait(millisecondsTimeout, CancellationToken.None);
@@ -612,6 +620,7 @@ namespace System.Threading
         /// canceled.</exception>
         /// <exception cref="System.ObjectDisposedException">The current instance has already been
         /// disposed.</exception>
+        [UnsupportedOSPlatform("browser")]
         public bool SignalAndWait(int millisecondsTimeout, CancellationToken cancellationToken)
         {
             ThrowIfDisposed();
@@ -855,6 +864,7 @@ namespace System.Threading
         /// <param name="token">cancellation token passed to SignalAndWait</param>
         /// <param name="observedPhase">The current phase number for this thread</param>
         /// <returns>True if the event is set or the phase number changed, false if the timeout expired</returns>
+        [UnsupportedOSPlatform("browser")]
         private bool DiscontinuousWait(ManualResetEventSlim currentPhaseEvent, int totalTimeout, CancellationToken token, long observedPhase)
         {
             int maxWait = 100; // 100 ms
index 7ef433c..dc3ad70 100644 (file)
@@ -8,6 +8,7 @@
 // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
 
 using System.Diagnostics;
+using System.Runtime.Versioning;
 
 namespace System.Threading
 {
@@ -414,6 +415,7 @@ namespace System.Threading
         /// </remarks>
         /// <exception cref="System.ObjectDisposedException">The current instance has already been
         /// disposed.</exception>
+        [UnsupportedOSPlatform("browser")]
         public void Wait()
         {
             Wait(Timeout.Infinite, CancellationToken.None);
@@ -437,6 +439,7 @@ namespace System.Threading
         /// canceled.</exception>
         /// <exception cref="System.ObjectDisposedException">The current instance has already been
         /// disposed.</exception>
+        [UnsupportedOSPlatform("browser")]
         public void Wait(CancellationToken cancellationToken)
         {
             Wait(Timeout.Infinite, cancellationToken);
@@ -456,6 +459,7 @@ namespace System.Threading
         /// than <see cref="int.MaxValue"/>.</exception>
         /// <exception cref="System.ObjectDisposedException">The current instance has already been
         /// disposed.</exception>
+        [UnsupportedOSPlatform("browser")]
         public bool Wait(TimeSpan timeout)
         {
             long totalMilliseconds = (long)timeout.TotalMilliseconds;
@@ -486,6 +490,7 @@ namespace System.Threading
         /// disposed.</exception>
         /// <exception cref="System.OperationCanceledException"><paramref name="cancellationToken"/> has
         /// been canceled.</exception>
+        [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.</exception>
         /// <exception cref="System.ObjectDisposedException">The current instance has already been
         /// disposed.</exception>
+        [UnsupportedOSPlatform("browser")]
         public bool Wait(int millisecondsTimeout)
         {
             return Wait(millisecondsTimeout, CancellationToken.None);
@@ -531,6 +537,7 @@ namespace System.Threading
         /// disposed.</exception>
         /// <exception cref="System.OperationCanceledException"><paramref name="cancellationToken"/> has
         /// been canceled.</exception>
+        [UnsupportedOSPlatform("browser")]
         public bool Wait(int millisecondsTimeout, CancellationToken cancellationToken)
         {
             if (millisecondsTimeout < -1)
index 90a8e51..1d49a2c 100644 (file)
@@ -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
         /// <summary>
         /// Helper function that restores the lock to the original state indicated by parameters
         /// </summary>
+        [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
index d6c0a60..9520218 100644 (file)
@@ -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() { }
index 1388352..e387159 100644 (file)
@@ -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
index 2cc0efd..3851ed0 100644 (file)
@@ -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);
                     }
index 3a991ca..a022034 100644 (file)
@@ -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)
index ef1f8e2..ddbf60b 100644 (file)
@@ -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<object> GetEntityAsync(System.Uri absoluteUri, string? role, System.Type? ofObjectToReturn) { throw null; }
index e123641..6a40f5f 100644 (file)
@@ -1,4 +1,4 @@
-<Project Sdk="Microsoft.NET.Sdk">
+<Project Sdk="Microsoft.NET.Sdk">
   <!-- Generate Mono corelib version file -->
   <Import Project="GenerateMonoCoreLibVersionFile.targets" />
 
       <Compile Include="$(BclSourcesRoot)\System\TypeSpec.cs" />
   </ItemGroup>
 
+  <!-- Enable unsupported browser warnings -->
+  <ItemGroup Condition="'$(TargetsBrowser)' == 'true' or '$(TargetsAnyOS)' == 'true'">
+    <SupportedPlatform Include="browser"/>
+  </ItemGroup>
+
   <Import Project="$(LibrariesProjectRoot)\System.Private.CoreLib\src\System.Private.CoreLib.Shared.projitems" Label="Shared" />
 
   <Target Name="CopyCoreLibToBinDir" AfterTargets="Build">