diff --git a/src/libraries/Common/src/System/Obsoletions.cs b/src/libraries/Common/src/System/Obsoletions.cs index 0fc0731ad13444..45decebe154745 100644 --- a/src/libraries/Common/src/System/Obsoletions.cs +++ b/src/libraries/Common/src/System/Obsoletions.cs @@ -42,5 +42,8 @@ internal static class Obsoletions internal const string CodeBaseMessage = "Assembly.CodeBase and Assembly.EscapedCodeBase are only included for .NET Framework compatibility. Use Assembly.Location instead."; internal const string CodeBaseDiagId = "SYSLIB0012"; + + internal const string WebRequestMessage = "Use HttpClient instead."; + internal const string WebRequestDiagId = "SYSLIB0014"; } } diff --git a/src/libraries/System.Net.Mail/src/System/Net/Mail/SmtpClient.cs b/src/libraries/System.Net.Mail/src/System/Net/Mail/SmtpClient.cs index 8bf41285740fb9..9e87770828ebad 100644 --- a/src/libraries/System.Net.Mail/src/System/Net/Mail/SmtpClient.cs +++ b/src/libraries/System.Net.Mail/src/System/Net/Mail/SmtpClient.cs @@ -287,7 +287,9 @@ public ServicePoint ServicePoint // This has some subtle impact on behavior, e.g. the returned ServicePoint's Address property will // be usable, whereas in .NET Framework it throws an exception that "This property is not supported for // protocols that do not use URI." +#pragma warning disable SYSLIB0014 return _servicePoint ??= ServicePointManager.FindServicePoint(new Uri("mailto:" + _host + ":" + _port)); +#pragma warning restore SYSLIB0014 } } diff --git a/src/libraries/System.Net.Requests/ref/System.Net.Requests.cs b/src/libraries/System.Net.Requests/ref/System.Net.Requests.cs index 1fc5c6d2bdbb6d..16570cd4a8154d 100644 --- a/src/libraries/System.Net.Requests/ref/System.Net.Requests.cs +++ b/src/libraries/System.Net.Requests/ref/System.Net.Requests.cs @@ -114,7 +114,9 @@ public enum FtpStatusCode } public sealed partial class FtpWebRequest : System.Net.WebRequest { +#pragma warning disable SYSLIB0014 internal FtpWebRequest() { } +#pragma warning restore SYSLIB0014 public System.Security.Cryptography.X509Certificates.X509CertificateCollection ClientCertificates { get { throw null; } set { } } public override string? ConnectionGroupName { get { throw null; } set { } } public override long ContentLength { get { throw null; } set { } } @@ -171,7 +173,7 @@ public GlobalProxySelection() { } public delegate void HttpContinueDelegate(int StatusCode, System.Net.WebHeaderCollection httpHeaders); public partial class HttpWebRequest : System.Net.WebRequest, System.Runtime.Serialization.ISerializable { - [System.ObsoleteAttribute("Serialization is obsoleted for this type. https://go.microsoft.com/fwlink/?linkid=14202")] + [System.ObsoleteAttribute("Use HttpClient instead.", DiagnosticId = "SYSLIB0014", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")] protected HttpWebRequest(System.Runtime.Serialization.SerializationInfo serializationInfo, System.Runtime.Serialization.StreamingContext streamingContext) { } public string? Accept { get { throw null; } set { } } public System.Uri Address { get { throw null; } } @@ -333,7 +335,9 @@ public enum WebExceptionStatus } public abstract partial class WebRequest : System.MarshalByRefObject, System.Runtime.Serialization.ISerializable { + [System.ObsoleteAttribute("Use HttpClient instead.", DiagnosticId = "SYSLIB0014", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")] protected WebRequest() { } + [System.ObsoleteAttribute("Use HttpClient instead.", DiagnosticId = "SYSLIB0014", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")] protected WebRequest(System.Runtime.Serialization.SerializationInfo serializationInfo, System.Runtime.Serialization.StreamingContext streamingContext) { } public System.Net.Security.AuthenticationLevel AuthenticationLevel { get { throw null; } set { } } public virtual System.Net.Cache.RequestCachePolicy? CachePolicy { get { throw null; } set { } } @@ -354,10 +358,15 @@ protected WebRequest(System.Runtime.Serialization.SerializationInfo serializatio public virtual void Abort() { } public virtual System.IAsyncResult BeginGetRequestStream(System.AsyncCallback? callback, object? state) { throw null; } public virtual System.IAsyncResult BeginGetResponse(System.AsyncCallback? callback, object? state) { throw null; } + [System.ObsoleteAttribute("Use HttpClient instead.", DiagnosticId = "SYSLIB0014", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")] public static System.Net.WebRequest Create(string requestUriString) { throw null; } + [System.ObsoleteAttribute("Use HttpClient instead.", DiagnosticId = "SYSLIB0014", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")] public static System.Net.WebRequest Create(System.Uri requestUri) { throw null; } + [System.ObsoleteAttribute("Use HttpClient instead.", DiagnosticId = "SYSLIB0014", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")] public static System.Net.WebRequest CreateDefault(System.Uri requestUri) { throw null; } + [System.ObsoleteAttribute("Use HttpClient instead.", DiagnosticId = "SYSLIB0014", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")] public static System.Net.HttpWebRequest CreateHttp(string requestUriString) { throw null; } + [System.ObsoleteAttribute("Use HttpClient instead.", DiagnosticId = "SYSLIB0014", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")] public static System.Net.HttpWebRequest CreateHttp(System.Uri requestUri) { throw null; } public virtual System.IO.Stream EndGetRequestStream(System.IAsyncResult asyncResult) { throw null; } public virtual System.Net.WebResponse EndGetResponse(System.IAsyncResult asyncResult) { throw null; } diff --git a/src/libraries/System.Net.Requests/src/System/Net/FileWebRequest.cs b/src/libraries/System.Net.Requests/src/System/Net/FileWebRequest.cs index ce96ff6fcc8fa1..86cb50a5012cb0 100644 --- a/src/libraries/System.Net.Requests/src/System/Net/FileWebRequest.cs +++ b/src/libraries/System.Net.Requests/src/System/Net/FileWebRequest.cs @@ -25,6 +25,7 @@ public class FileWebRequest : WebRequest, ISerializable private bool _syncHint; private int _aborted; +#pragma warning disable SYSLIB0014 internal FileWebRequest(Uri uri) { if (uri.Scheme != (object)Uri.UriSchemeFile) @@ -40,6 +41,7 @@ protected FileWebRequest(SerializationInfo serializationInfo, StreamingContext s { throw new PlatformNotSupportedException(); } +#pragma warning restore SYSLIB0014 void ISerializable.GetObjectData(SerializationInfo serializationInfo, StreamingContext streamingContext) => GetObjectData(serializationInfo, streamingContext); diff --git a/src/libraries/System.Net.Requests/src/System/Net/FtpWebRequest.cs b/src/libraries/System.Net.Requests/src/System/Net/FtpWebRequest.cs index dacc4b7cf96219..70de06c5a1c87e 100644 --- a/src/libraries/System.Net.Requests/src/System/Net/FtpWebRequest.cs +++ b/src/libraries/System.Net.Requests/src/System/Net/FtpWebRequest.cs @@ -479,7 +479,9 @@ public override string? ConnectionGroupName } } +#pragma warning disable SYSLIB0014 public ServicePoint ServicePoint => _servicePoint ??= ServicePointManager.FindServicePoint(_uri); +#pragma warning restore SYSLIB0014 internal bool Aborted { @@ -489,7 +491,9 @@ internal bool Aborted } } +#pragma warning disable SYSLIB0014 internal FtpWebRequest(Uri uri) +#pragma warning restore SYSLIB0014 { if (NetEventSource.Log.IsEnabled()) NetEventSource.Info(this, uri); diff --git a/src/libraries/System.Net.Requests/src/System/Net/HttpWebRequest.cs b/src/libraries/System.Net.Requests/src/System/Net/HttpWebRequest.cs index f305ea0901dc5d..327e60cbcdb143 100644 --- a/src/libraries/System.Net.Requests/src/System/Net/HttpWebRequest.cs +++ b/src/libraries/System.Net.Requests/src/System/Net/HttpWebRequest.cs @@ -160,11 +160,12 @@ public bool AreParametersAcceptableForCaching() private const string ContinueHeader = "100-continue"; private const string ChunkedHeader = "chunked"; + [Obsolete(Obsoletions.WebRequestMessage, DiagnosticId = Obsoletions.WebRequestDiagId, UrlFormat = Obsoletions.SharedUrlFormat)] public HttpWebRequest() { } - [Obsolete("Serialization is obsoleted for this type. https://go.microsoft.com/fwlink/?linkid=14202")] + [Obsolete(Obsoletions.WebRequestMessage, DiagnosticId = Obsoletions.WebRequestDiagId, UrlFormat = Obsoletions.SharedUrlFormat)] protected HttpWebRequest(SerializationInfo serializationInfo, StreamingContext streamingContext) : base(serializationInfo, streamingContext) { throw new PlatformNotSupportedException(); @@ -180,10 +181,12 @@ protected override void GetObjectData(SerializationInfo serializationInfo, Strea throw new PlatformNotSupportedException(); } +#pragma warning disable SYSLIB0014 internal HttpWebRequest(Uri uri) { _requestUri = uri; } +#pragma warning restore SYSLIB0014 private void SetSpecialHeaders(string HeaderName, string? value) { @@ -753,7 +756,9 @@ public HttpContinueDelegate? ContinueDelegate } } +#pragma warning disable SYSLIB0014 public ServicePoint ServicePoint => _servicePoint ??= ServicePointManager.FindServicePoint(Address, Proxy); +#pragma warning restore SYSLIB0014 public RemoteCertificateValidationCallback? ServerCertificateValidationCallback { get; set; } diff --git a/src/libraries/System.Net.Requests/src/System/Net/WebRequest.cs b/src/libraries/System.Net.Requests/src/System/Net/WebRequest.cs index 8f354beae3c599..bcdce17c44bf88 100644 --- a/src/libraries/System.Net.Requests/src/System/Net/WebRequest.cs +++ b/src/libraries/System.Net.Requests/src/System/Net/WebRequest.cs @@ -33,8 +33,10 @@ public WebRequestPrefixElement(string prefix, IWebRequestCreate creator) internal const int DefaultTimeoutMilliseconds = 100 * 1000; + [Obsolete(Obsoletions.WebRequestMessage, DiagnosticId = Obsoletions.WebRequestDiagId, UrlFormat = Obsoletions.SharedUrlFormat)] protected WebRequest() { } + [Obsolete(Obsoletions.WebRequestMessage, DiagnosticId = Obsoletions.WebRequestDiagId, UrlFormat = Obsoletions.SharedUrlFormat)] protected WebRequest(SerializationInfo serializationInfo, StreamingContext streamingContext) { throw new PlatformNotSupportedException(); @@ -140,6 +142,7 @@ private static WebRequest Create(Uri requestUri, bool useUriBase) // // Returns: // Newly created WebRequest. + [Obsolete(Obsoletions.WebRequestMessage, DiagnosticId = Obsoletions.WebRequestDiagId, UrlFormat = Obsoletions.SharedUrlFormat)] public static WebRequest Create(string requestUriString) { if (requestUriString == null) @@ -160,6 +163,7 @@ public static WebRequest Create(string requestUriString) // // Returns: // Newly created WebRequest. + [Obsolete(Obsoletions.WebRequestMessage, DiagnosticId = Obsoletions.WebRequestDiagId, UrlFormat = Obsoletions.SharedUrlFormat)] public static WebRequest Create(Uri requestUri) { if (requestUri == null) @@ -181,6 +185,7 @@ public static WebRequest Create(Uri requestUri) // // Returns: // Newly created WebRequest. + [Obsolete(Obsoletions.WebRequestMessage, DiagnosticId = Obsoletions.WebRequestDiagId, UrlFormat = Obsoletions.SharedUrlFormat)] public static WebRequest CreateDefault(Uri requestUri) { if (requestUri == null) @@ -191,6 +196,7 @@ public static WebRequest CreateDefault(Uri requestUri) return Create(requestUri, true); } + [Obsolete(Obsoletions.WebRequestMessage, DiagnosticId = Obsoletions.WebRequestDiagId, UrlFormat = Obsoletions.SharedUrlFormat)] public static HttpWebRequest CreateHttp(string requestUriString) { if (requestUriString == null) @@ -200,6 +206,7 @@ public static HttpWebRequest CreateHttp(string requestUriString) return CreateHttp(new Uri(requestUriString)); } + [Obsolete(Obsoletions.WebRequestMessage, DiagnosticId = Obsoletions.WebRequestDiagId, UrlFormat = Obsoletions.SharedUrlFormat)] public static HttpWebRequest CreateHttp(Uri requestUri) { if (requestUri == null) diff --git a/src/libraries/System.Net.Requests/tests/System.Net.Requests.Tests.csproj b/src/libraries/System.Net.Requests/tests/System.Net.Requests.Tests.csproj index ecb8a780af90ce..be502f34b17d8e 100644 --- a/src/libraries/System.Net.Requests/tests/System.Net.Requests.Tests.csproj +++ b/src/libraries/System.Net.Requests/tests/System.Net.Requests.Tests.csproj @@ -5,6 +5,7 @@ $(NetCoreAppCurrent) $(DefineConstants);NETSTANDARD true + $(NoWarn);SYSLIB0014 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 3227108c37b542..d7adfc5a1484e9 100644 --- a/src/libraries/System.Net.ServicePoint/ref/System.Net.ServicePoint.cs +++ b/src/libraries/System.Net.ServicePoint/ref/System.Net.ServicePoint.cs @@ -56,8 +56,11 @@ internal ServicePointManager() { } public static System.Net.SecurityProtocolType SecurityProtocol { get { throw null; } set { } } public static System.Net.Security.RemoteCertificateValidationCallback? ServerCertificateValidationCallback { get { throw null; } set { } } public static bool UseNagleAlgorithm { get { throw null; } set { } } + [System.ObsoleteAttribute("Use HttpClient instead.", DiagnosticId = "SYSLIB0014", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")] public static System.Net.ServicePoint FindServicePoint(string uriString, System.Net.IWebProxy? proxy) { throw null; } + [System.ObsoleteAttribute("Use HttpClient instead.", DiagnosticId = "SYSLIB0014", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")] public static System.Net.ServicePoint FindServicePoint(System.Uri address) { throw null; } + [System.ObsoleteAttribute("Use HttpClient instead.", DiagnosticId = "SYSLIB0014", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")] public static System.Net.ServicePoint FindServicePoint(System.Uri address, System.Net.IWebProxy? proxy) { throw null; } public static void SetTcpKeepAlive(bool enabled, int keepAliveTime, int keepAliveInterval) { } } diff --git a/src/libraries/System.Net.ServicePoint/src/System.Net.ServicePoint.csproj b/src/libraries/System.Net.ServicePoint/src/System.Net.ServicePoint.csproj index 24acad57cf4a90..54aae967357154 100644 --- a/src/libraries/System.Net.ServicePoint/src/System.Net.ServicePoint.csproj +++ b/src/libraries/System.Net.ServicePoint/src/System.Net.ServicePoint.csproj @@ -11,6 +11,8 @@ + 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 228017952f3d04..267610d2d675f5 100644 --- a/src/libraries/System.Net.ServicePoint/src/System/Net/ServicePointManager.cs +++ b/src/libraries/System.Net.ServicePoint/src/System/Net/ServicePointManager.cs @@ -104,10 +104,13 @@ public static int DnsRefreshTimeout public static EncryptionPolicy EncryptionPolicy { get; } = EncryptionPolicy.RequireEncryption; + [Obsolete(Obsoletions.WebRequestMessage, DiagnosticId = Obsoletions.WebRequestDiagId, UrlFormat = Obsoletions.SharedUrlFormat)] public static ServicePoint FindServicePoint(Uri address) => FindServicePoint(address, null); + [Obsolete(Obsoletions.WebRequestMessage, DiagnosticId = Obsoletions.WebRequestDiagId, UrlFormat = Obsoletions.SharedUrlFormat)] public static ServicePoint FindServicePoint(string uriString, IWebProxy? proxy) => FindServicePoint(new Uri(uriString), proxy); + [Obsolete(Obsoletions.WebRequestMessage, DiagnosticId = Obsoletions.WebRequestDiagId, UrlFormat = Obsoletions.SharedUrlFormat)] public static ServicePoint FindServicePoint(Uri address, IWebProxy? proxy) { if (address == null) diff --git a/src/libraries/System.Net.ServicePoint/tests/System.Net.ServicePoint.Tests.csproj b/src/libraries/System.Net.ServicePoint/tests/System.Net.ServicePoint.Tests.csproj index c82e88cf2d9074..cad52ea6fd2afc 100644 --- a/src/libraries/System.Net.ServicePoint/tests/System.Net.ServicePoint.Tests.csproj +++ b/src/libraries/System.Net.ServicePoint/tests/System.Net.ServicePoint.Tests.csproj @@ -2,9 +2,10 @@ true $(NetCoreAppCurrent) + $(NoWarn);SYSLIB0014 - \ No newline at end of file + diff --git a/src/libraries/System.Net.WebClient/ref/System.Net.WebClient.cs b/src/libraries/System.Net.WebClient/ref/System.Net.WebClient.cs index 4b035a4ecdd1d8..151ee487f4866b 100644 --- a/src/libraries/System.Net.WebClient/ref/System.Net.WebClient.cs +++ b/src/libraries/System.Net.WebClient/ref/System.Net.WebClient.cs @@ -72,6 +72,7 @@ public partial class UploadValuesCompletedEventArgs : System.ComponentModel.Asyn public delegate void UploadValuesCompletedEventHandler(object sender, System.Net.UploadValuesCompletedEventArgs e); public partial class WebClient : System.ComponentModel.Component { + [System.ObsoleteAttribute("Use HttpClient instead.", DiagnosticId = "SYSLIB0014", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")] public WebClient() { } [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] [System.ObsoleteAttribute("This API supports the .NET Framework infrastructure and is not intended to be used directly from your code.", true)] diff --git a/src/libraries/System.Net.WebClient/src/System.Net.WebClient.csproj b/src/libraries/System.Net.WebClient/src/System.Net.WebClient.csproj index 8f7d3b5c98891b..48a1a9c82537cc 100644 --- a/src/libraries/System.Net.WebClient/src/System.Net.WebClient.csproj +++ b/src/libraries/System.Net.WebClient/src/System.Net.WebClient.csproj @@ -23,6 +23,8 @@ Link="Common\System\HexConverter.cs" /> + diff --git a/src/libraries/System.Net.WebClient/src/System/Net/WebClient.cs b/src/libraries/System.Net.WebClient/src/System/Net/WebClient.cs index 129368a5d97251..37e0a0f704dfa3 100644 --- a/src/libraries/System.Net.WebClient/src/System/Net/WebClient.cs +++ b/src/libraries/System.Net.WebClient/src/System/Net/WebClient.cs @@ -53,6 +53,7 @@ public class WebClient : Component private SendOrPostCallback? _reportDownloadProgressChanged; private SendOrPostCallback? _reportUploadProgressChanged; + [Obsolete(Obsoletions.WebRequestMessage, DiagnosticId = Obsoletions.WebRequestDiagId, UrlFormat = Obsoletions.SharedUrlFormat)] public WebClient() { // We don't know if derived types need finalizing, but WebClient doesn't. @@ -216,7 +217,10 @@ public IWebProxy? Proxy protected virtual WebRequest GetWebRequest(Uri address) { +#pragma warning disable SYSLIB0014 WebRequest request = WebRequest.Create(address); +#pragma warning restore SYSLIB0014 + CopyHeadersTo(request); if (Credentials != null) diff --git a/src/libraries/System.Net.WebClient/tests/System.Net.WebClient.Tests.csproj b/src/libraries/System.Net.WebClient/tests/System.Net.WebClient.Tests.csproj index 140cbb8132dd0b..bd9c2cc5549542 100644 --- a/src/libraries/System.Net.WebClient/tests/System.Net.WebClient.Tests.csproj +++ b/src/libraries/System.Net.WebClient/tests/System.Net.WebClient.Tests.csproj @@ -2,6 +2,7 @@ $(NetCoreAppCurrent) $(DefineConstants);NETSTANDARD + $(NoWarn);SYSLIB0014 diff --git a/src/libraries/System.Windows.Extensions/src/System/Media/SoundPlayer.cs b/src/libraries/System.Windows.Extensions/src/System/Media/SoundPlayer.cs index da68f709c4a250..74c397b26d10eb 100644 --- a/src/libraries/System.Windows.Extensions/src/System/Media/SoundPlayer.cs +++ b/src/libraries/System.Windows.Extensions/src/System/Media/SoundPlayer.cs @@ -259,7 +259,9 @@ private void LoadSync() // setup the http stream if (_uri != null && !_uri.IsFile && _stream == null) { +#pragma warning disable SYSLIB0014 WebRequest webRequest = WebRequest.Create(_uri); +#pragma warning restore SYSLIB0014 webRequest.Timeout = LoadTimeout; WebResponse webResponse; @@ -479,7 +481,9 @@ private async Task CopyStreamAsync(CancellationToken cancellationToken) // setup the http stream if (_uri != null && !_uri.IsFile && _stream == null) { +#pragma warning disable SYSLIB0014 WebRequest webRequest = WebRequest.Create(_uri); +#pragma warning restore SYSLIB0014 using (cancellationToken.Register(r => ((WebRequest)r).Abort(), webRequest)) { WebResponse webResponse = await webRequest.GetResponseAsync().ConfigureAwait(false);