SYSLIB0066:IStartupValidator 已過時

從 .NET 11 開始,IStartupValidator 已淘汰。 當你參考或實作此介面時,編譯器會產生警告 SYSLIB0066,訊息為 Implement IAsyncStartupValidator instead.。介面保持可用性且功能正常,以維持相容性。

淘汰的原因

主機啟動透過 StartAsync 具有非同步的入口點。 新的自訂啟動驗證器應該使用 IAsyncStartupValidator。 它的非同步 ValidateAsync 合約意味著非同步實作不需要提供未使用的同步 Validate 方法。 這兩個介面是獨立的。

Workaround

若要遷移自訂的啟動驗證器,請實作並註冊 IAsyncStartupValidator 。 當驗證需要這麼做時,在 ValidateAsync 中使用非同步操作,並轉發取消權杖。 僅在其提供的啟動驗證介面下註冊實作;不要同時在 IStartupValidator 和 IAsyncStartupValidator 之下註冊它。

那些只呼叫 OptionsBuilder<TOptions>.ValidateOnStart() 且不直接實作啟動驗證介面的應用程式,通常不需要更改程式碼。

隱藏警告

如果你必須使用過時的介面,可以在程式碼或專案檔案中抑制警告。

若要抑制單一違規項目,請在原始檔案中加入預處理器指令,先停用再重新啟用警告。

#pragma warning disable SYSLIB0066

// Code that uses the obsolete interface.

#pragma warning restore SYSLIB0066

要抑制專案中的所有 SYSLIB0066 警告,請在專案檔案中新增一個 <NoWarn> 屬性。

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

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