編譯器警告 (層級 1) CS0688
更新:2007 年 11 月
錯誤訊息
'method1' 有連結要求,但是會覆寫或實作沒有連結要求的 'method2'。可能會產生安全性弱點。
在衍生類別方法中設定的連結要求,可輕易地藉由呼叫基底類別 (Base Class) 方法而規避。若要關閉安全性弱點,基底類別方法也需要使用連結要求。如需詳細資訊,請參閱 Demand 和 LinkDemand 的比較。
範例
下列範例會產生 CS0688:若要解決此警告但不修改基底類別,請移除覆寫方法中的安全屬性 (Security Attribute)。不過這樣不會解決安全性問題。
// CS0688.cs
// compile with: /W:1
using System;
using System.Security.Permissions;
class Base
{
//Uncomment the following line to close the security hole
//[FileIOPermission(SecurityAction.LinkDemand, All=@"C:\\")]
public virtual void DoScaryFileStuff()
{
}
}
class Derived: Base
{
[FileIOPermission(SecurityAction.LinkDemand, All=@"C:\\")] // CS0688
public override void DoScaryFileStuff()
{
}
static void Main()
{
}
}