編譯器錯誤 CS0012
更新:2007 年 11 月
錯誤訊息
型別 'type' 是定義在未參考的組件中。您必須將參考加入至組件 'assembly'。
找不到參考型別的定義。如果編譯中沒有包含需要的 .DLL 檔,就可能發生這個錯誤。如需詳細資訊,請參閱加入參考對話方塊和 /reference (匯入中繼資料) (C# 編譯器選項)。
下列編譯序列將會導致 CS0012:
// cs0012a.cs
// compile with: /target:library
public class A {}
然後是:
// cs0012b.cs
// compile with: /target:library /reference:cs0012a.dll
public class B
{
public static A f()
{
return new A();
}
}
然後是:
// cs0012c.cs
// compile with: /reference:cs0012b.dll
class C
{
public static void Main()
{
object o = B.f(); // CS0012
}
}
您可以使用 /reference:b.dll;a.dll 進行編譯,解決 CS0012 錯誤。