Nóta
Teastaíonn údarú chun rochtain a fháil ar an leathanach seo. Is féidir leat triail a bhaint as shíniú isteach nó eolairí a athrú.
Teastaíonn údarú chun rochtain a fháil ar an leathanach seo. Is féidir leat triail a bhaint as eolairí a athrú.
The following System.Security.Cryptography methods are obsolete, starting in .NET 7. Using them in code generates warning SYSLIB0045 at compile time. Each of these factory methods accepts a string argument that represents the algorithm name. These methods call into CryptoConfig.CreateFromName and cast the result to the return type.
- Aes.Create(String)
- AsymmetricAlgorithm.Create(String)
- DES.Create(String)
- ECDiffieHellman.Create(String)
- ECDsa.Create(String)
- HashAlgorithm.Create(String)
- KeyedHashAlgorithm.Create(String)
- RandomNumberGenerator.Create(String)
- RC2.Create(String)
- Rijndael.Create(String)
- RSA.Create(String)
- SHA1.Create(String)
- SHA256.Create(String)
- SHA384.Create(String)
- SHA512.Create(String)
- SymmetricAlgorithm.Create(String)
- TripleDES.Create(String)
These methods were marked [Obsolete] because in trimmed applications, they can return null when they wouldn't in non-trimmed applications. Also, in non-trimmed applications, the exception-based behaviors of these methods occasionally surprises callers, and many of the well-known identifiers are associated with types that are themselves marked [Obsolete].
Workaround
Calls that pass a constant string should be changed to either the parameterless factory method or a strong call to create the appropriate type. For example, a call to Aes.Create("AES") can be replaced with either Aes.Create() or new AesCryptoServiceProvider(). Since the AesCryptoServiceProvider type is also marked [Obsolete], Aes.Create() is the preferred replacement.
Calls that pass a non-constant string can either use their own lookup table or be changed to call CryptoConfig.CreateFromName directly.
Suppress a warning
If you must use the obsolete APIs, you can suppress the warning in code or in your project file.
To suppress only a single violation, add preprocessor directives to your source file to disable and then re-enable the warning.
// Disable the warning.
#pragma warning disable SYSLIB0045
// Code that uses obsolete API.
// ...
// Re-enable the warning.
#pragma warning restore SYSLIB0045
To suppress all the SYSLIB0045 warnings in your project, add a <NoWarn> property to your project file.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
...
<NoWarn>$(NoWarn);SYSLIB0045</NoWarn>
</PropertyGroup>
</Project>
For more information, see Suppress warnings.