共用方式為


SYSLIB0031:EncodeOID 已過時

CryptoConfig.EncodeOID(String) 方法自 .NET 6 起被標記為過時。 在程式碼中使用此 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>

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