共用方式為


編譯器錯誤 CS1613

更新:2007 年 11 月

錯誤訊息

找不到介面 'interface' 的 Managed coclass 包裝函式類別 'class' (您是否遺漏了組件參考?)

嘗試將來自介面的 COM 物件執行個體化。該介面有 ComImportCoClass 屬性 (Attribute),但是編譯器找不到指定給 CoClass 屬性的型別。

若要解決這個錯誤,您可嘗試下列方法之一:

  • 將參考加入擁有 coclass 的組件內 (通常介面和 coclass 都會位於相同的組件內)。如需相關資訊,請參閱 /reference加入參考對話方塊

  • 修正介面上的 CoClass 屬性。

下列範例示範 CoClassAttribute 的正確用法:

// CS1613.cs
using System;
using System.Runtime.InteropServices;

[Guid("1FFD7840-E82D-4268-875C-80A160C23296")]
[ComImport()]
[CoClass(typeof(A))]
public interface IA{}
public class A : IA {}

public class AA
{
   public static void Main()
   {
      IA i;
      i = new IA(); // This is equivalent to new A().
                    // because of the CoClass attribute on IA
   }
}