编译器错误 CS1613
更新:2007 年 11 月
错误消息
无法找到接口“interface”的托管 coclass 包装类“class”(是否缺少程序集引用?)
试图从接口实例化 COM 对象。该接口具有 ComImport 和 CoClass 属性,但编译器无法找到为 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
}
}