Share via


將 RCW 轉換為 InterfaceIsIInspectable 介面會擲回 PlatformNotSupportedException

將執行階段可呼叫包裝函式 (RCW) 轉換成標記為 InterfaceIsIInspectable 的介面現會擲回 PlatformNotSupportedException。 這項變更是從 .NET 移除 WinRT 支援的後續。

導入的版本

.NET 5

變更描述

在先前的 .NET 版本中,將 RCW 轉換成標記為 InterfaceIsIInspectable 介面時,可正常運作。 自 .NET 5 起,將 RCW 轉換成標記為 InterfaceIsIInspectable 的介面,會在轉換階段擲回 PlatformNotSupportedException

變更原因

InterfaceIsIInspectable 支援已經移除。 由於執行階段中已不存在基礎支援,擲回 PlatformNotSupportedException 可讓失敗平順地發生。 擲回例外狀況也可您更容易發現此功能不再受到支援。

  • 若您可以在 Windows 執行階段中繼資料 (WinMD) 檔案中定義介面,請改為使用 C#/WinRT 工具。

  • 否則,請將介面標示為 InterfaceIsIUnknown 而非 InterfaceIsIInspectable,並將三個虛擬項目新增至 InterfaceIsIInspectable 方法的介面開頭。 下列程式碼片段為範例。

    [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
    interface IMine
    {
        // Do not call these three methods.
        // They're exclusively to fill in the slots in the vtable.
        void GetIIdsSlot();
        void GetRuntimeClassNameSlot();
        void GetTrustLevelSlot();
    
        // The original members of the IMine interface go here.
        ...
    }
    

受影響的 API