Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
The FromXmlString and ToXmlString methods that are on elliptic curve cryptography (ECC) types are obsolete, starting in .NET 7. Using them in code generates warning SYSLIB0042 at compile time. They were never implemented and always threw a PlatformNotSupportedException exception. The obsoletion affects the following methods:
- ECDiffieHellmanCng.FromXmlString(String, ECKeyXmlFormat)
- ECDiffieHellmanCng.ToXmlString(ECKeyXmlFormat)
- ECDiffieHellmanCngPublicKey.FromXmlString(String)
- ECDiffieHellmanCngPublicKey.ToXmlString()
- ECDiffieHellmanPublicKey.ToXmlString()
- ECDsaCng.FromXmlString(String, ECKeyXmlFormat)
- ECDsaCng.ToXmlString(ECKeyXmlFormat)
Workaround
Use a standard data format for exchanging elliptic curve (EC) keys.
Instead of ToXmlString, use ExportSubjectPublicKeyInfo or ExportPkcs8PrivateKey depending on whether you want the public or private key.
Instead of FromXmlString, use ImportSubjectPublicKeyInfo or ImportPkcs8PrivateKey depending on whether you want to import a public or private key.
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 SYSLIB0042
// Code that uses obsolete API.
// ...
// Re-enable the warning.
#pragma warning restore SYSLIB0042
To suppress all the SYSLIB0042 warnings in your project, add a <NoWarn> property to your project file.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
...
<NoWarn>$(NoWarn);SYSLIB0042</NoWarn>
</PropertyGroup>
</Project>
For more information, see Suppress warnings.