SYSLIB0031:EncodeOID 已淘汰

從 .NET 6 開始,CryptoConfig.EncodeOID(String) 方法會標示為已淘汰。 在程式碼中使用此 API 會在編譯時間產生警告 SYSLIB0031,並在執行階段擲回 PlatformNotSupportedException 例外狀況。

因應措施

請使用 System.Formats.Asn1 中提供的 ASN.1 功能。

隱藏警告

若您必須使用已淘汰的 API,您可以在程式碼或專案檔中隱藏警告。

若要只隱藏單一違規,請將前置處理器指示詞新增至原始程式碼檔案,以停用並重新啟用警告。

// Disable the warning.
#pragma warning disable SYSLIB0031

// Code that uses obsolete API.
// ...

// Re-enable the warning.
#pragma warning restore SYSLIB0031

若要隱藏專案中的所有 SYSLIB0031 警告,請將 <NoWarn> 屬性新增至專案檔。

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
   ...
   <NoWarn>$(NoWarn);SYSLIB0031</NoWarn>
  </PropertyGroup>
</Project>

如需詳細資訊,請參閱隱藏警告