API obsoletions with non-default diagnostic IDs (.NET 6)
Some APIs have been marked as obsolete, starting in .NET 6. This breaking change is specific to APIs that have been marked as obsolete with a custom diagnostic ID. Suppressing the default obsoletion diagnostic ID, which is CS0618 for the C# compiler, does not suppress the warnings that the compiler generates when these APIs are used.
Change description
In previous .NET versions, these APIs can be used without any build warning. In .NET 6 and later versions, use of these APIs produces a compile-time warning or error with a custom diagnostic ID. The use of custom diagnostic IDs allows you to suppress the obsoletion warnings individually instead of blanket-suppressing all obsoletion warnings.
The following table lists the custom diagnostic IDs and their corresponding warning messages for obsoleted APIs.
Diagnostic ID | Description | Severity |
---|---|---|
SYSLIB0013 | Uri.EscapeUriString(String) can corrupt the URI string in some cases. Consider using Uri.EscapeDataString(String) for query string components instead. | Warning |
SYSLIB0014 | WebRequest, HttpWebRequest, ServicePoint, and WebClient are obsolete. Use HttpClient instead. | Warning |
SYSLIB0015 | DisablePrivateReflectionAttribute has no effect in .NET 6+. | Warning |
SYSLIB0016 | Use the Graphics.GetContextInfo overloads that accept arguments for better performance and fewer allocations. | Warning |
SYSLIB0017 | Strong-name signing is not supported and throws PlatformNotSupportedException. | Warning |
SYSLIB0018 | Reflection-only loading is not supported and throws PlatformNotSupportedException. | Warning |
SYSLIB0019 | The System.Runtime.InteropServices.RuntimeEnvironment members SystemConfigurationFile, GetRuntimeInterfaceAsIntPtr(Guid, Guid), and GetRuntimeInterfaceAsObject(Guid, Guid) are no longer supported and throw PlatformNotSupportedException. | Warning |
SYSLIB0020 | JsonSerializerOptions.IgnoreNullValues is obsolete. To ignore null values when serializing, set DefaultIgnoreCondition to JsonIgnoreCondition.WhenWritingNull. | Warning |
SYSLIB0021 | Derived cryptographic types are obsolete. Use the Create method on the base type instead. |
Warning |
SYSLIB0022 | The Rijndael and RijndaelManaged types are obsolete. Use Aes instead. | Warning |
SYSLIB0023 | RNGCryptoServiceProvider is obsolete. To generate a random number, use one of the RandomNumberGenerator static methods instead. | Warning |
SYSLIB0024 | Creating and unloading AppDomains is not supported and throws an exception. | Warning |
SYSLIB0025 | SuppressIldasmAttribute has no effect in .NET 6+. | Warning |
SYSLIB0026 | X509Certificate and X509Certificate2 are immutable. Use the appropriate constructor to create a new certificate. | Warning |
SYSLIB0027 | PublicKey.Key is obsolete. Use the appropriate method to get the public key, such as GetRSAPublicKey(). | Warning |
SYSLIB0028 | X509Certificate2.PrivateKey is obsolete. Use the appropriate method to get the private key, such as RSACertificateExtensions.GetRSAPrivateKey(X509Certificate2), or use the X509Certificate2.CopyWithPrivateKey(ECDiffieHellman) method to create a new instance with a private key. | Warning |
SYSLIB0029 | ProduceLegacyHmacValues is obsolete. Producing legacy HMAC values is no longer supported. |
Warning |
SYSLIB0030 | HMACSHA1 always uses the algorithm implementation provided by the platform. Use a constructor without the useManagedSha1 parameter. |
Warning |
SYSLIB0031 | CryptoConfig.EncodeOID(String) is obsolete. Use the ASN.1 functionality provided in System.Formats.Asn1. | Warning |
SYSLIB0032 | Recovery from corrupted process state exceptions is not supported; HandleProcessCorruptedStateExceptionsAttribute is ignored. | Warning |
SYSLIB0033 | Rfc2898DeriveBytes.CryptDeriveKey(String, String, Int32, Byte[]) is obsolete and is not supported. Use PasswordDeriveBytes.CryptDeriveKey(String, String, Int32, Byte[]) instead. | Warning |
SYSLIB0034 | CmsSigner(CspParameters) is obsolete. Use an alternative constructor instead. | Warning |
SYSLIB0035 | SignerInfo.ComputeCounterSignature() is obsolete. Use the overload that accepts a CmsSigner instead. | Warning |
Version introduced
.NET 6
Recommended action
Follow the specific guidance provided for the each diagnostic ID using the URL link provided on the warning.
Warnings or errors for these obsoletions can't be suppressed using the standard diagnostic ID for obsolete types or members; use the custom
SYSLIBxxxx
diagnostic ID value instead.
Affected APIs
SYSLIB0013
SYSLIB0014
SYSLIB0015
SYSLIB0016
SYSLIB0017
SYSLIB0018
- System.Reflection.Assembly.ReflectionOnlyLoad
- System.Reflection.Assembly.ReflectionOnlyLoadFrom(String)
- System.Type.ReflectionOnlyGetType(String, Boolean, Boolean)
SYSLIB0019
- System.Runtime.InteropServices.RuntimeEnvironment.SystemConfigurationFile
- System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeInterfaceAsIntPtr(Guid, Guid)
- System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeInterfaceAsObject(Guid, Guid)
SYSLIB0020
SYSLIB0021
- System.Security.Cryptography.AesCryptoServiceProvider
- System.Security.Cryptography.AesManaged
- System.Security.Cryptography.DESCryptoServiceProvider
- System.Security.Cryptography.MD5CryptoServiceProvider
- System.Security.Cryptography.RC2CryptoServiceProvider
- System.Security.Cryptography.SHA1CryptoServiceProvider
- System.Security.Cryptography.SHA1Managed
- System.Security.Cryptography.SHA256Managed
- System.Security.Cryptography.SHA256CryptoServiceProvider
- System.Security.Cryptography.SHA384Managed
- System.Security.Cryptography.SHA384CryptoServiceProvider
- System.Security.Cryptography.SHA512Managed
- System.Security.Cryptography.SHA512CryptoServiceProvider
- System.Security.Cryptography.TripleDESCryptoServiceProvider