แก้ไข

แชร์ผ่าน


API obsoletions with non-default diagnostic IDs (.NET 7)

Some APIs have been marked as obsolete, starting in .NET 7. 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 7 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
SYSLIB0036 Regex.CompileToAssembly is obsolete and not supported. Use RegexGeneratorAttribute with the regular expression source generator instead. Warning
SYSLIB0037 AssemblyName members HashAlgorithm, ProcessorArchitecture, and VersionCompatibility are obsolete and not supported. Warning
SYSLIB0038 SerializationFormat.Binary is obsolete and should not be used. Warning
SYSLIB0039 TLS versions 1.0 and 1.1 have known vulnerabilities and are not recommended. Use a newer TLS version instead, or use SslProtocols.None to defer to OS defaults. Warning
SYSLIB0040 EncryptionPolicy.NoEncryption and EncryptionPolicy.AllowNoEncryption significantly reduce security and should not be used in production code. Warning
SYSLIB0041 The default hash algorithm and iteration counts in Rfc2898DeriveBytes constructors are outdated and insecure. Use a constructor that accepts the hash algorithm and the number of iterations. Warning
SYSLIB0042 ToXmlString and FromXmlString have no implementation for elliptic curve cryptography (ECC) types, and are obsolete. Use a standard import and export format such as ExportSubjectPublicKeyInfo or ImportSubjectPublicKeyInfo for public keys, and ExportPkcs8PrivateKey or ImportPkcs8PrivateKey for private keys. Warning
SYSLIB0043 ECDiffieHellmanPublicKey.ToByteArray() and the associated constructor do not have a consistent and interoperable implementation on all platforms. Use ECDiffieHellmanPublicKey.ExportSubjectPublicKeyInfo() instead. Warning
SYSLIB0044 AssemblyName.CodeBase and AssemblyName.EscapedCodeBase are obsolete. Warning
SYSLIB0045 Cryptographic factory methods accepting an algorithm name are obsolete. Use the parameterless Create factory method on the algorithm type instead. Warning
SYSLIB0047 XmlSecureResolver is obsolete. Use XmlResolver.ThrowingResolver instead to forbid resolution of external XML resources. Warning

Version introduced

.NET 7

Type of breaking change

These obsoletions can affect source compatibility.

  • 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

SYSLIB0036

SYSLIB0037

SYSLIB0038

SYSLIB0039

SYSLIB0040

SYSLIB0041

SYSLIB0042

SYSLIB0043

SYSLIB0045

SYSLIB0047

See also