編譯器警告 (層級 2) CS3021
更新:2007 年 11 月
錯誤訊息
'type' 不需要 CLSCompliant 屬性,因為組件沒有 CLSCompliant 屬性
如果 [CLSCompliant(false)] 出現在組件的類別中,而該組件的組件層級 CLSCompliant 屬性 (Attribute) 未設定成 true (亦即 [assembly: CLSCompliant(true)] 這一行),便會發生這個警告。由於組件沒有將本身宣告為符合 CLS 標準,所以組件中的任何項目都不需要將本身宣告為不符合 CLS 標準,因為原本就假設為不符合 CLS 標準。如需 CLS 標準符合性的詳細資訊,請參閱撰寫符合 CLS 標準的程式碼。
若要排除這個警告,請移除屬性或加入組件層級屬性。
範例
下列範例會產生 CS3021:
// CS3021.cs
using System;
// Uncomment the following line to declare the assembly CLS Compliant,
// and avoid the warning without removing the attribute on the class.
//[assembly: CLSCompliant(true)]
// Remove the next line to avoid the warning.
[CLSCompliant(false)] // CS3021
public class C
{
public static void Main()
{
}
}