更新:2007 年 11 月

错误消息

“method1”具有链接要求,但重写或实现的“method2”没有链接要求。可能存在安全漏洞。

对派生类方法设置的链接要求,可以通过调用基类方法轻松规避此要求。若要关闭此安全漏洞,基类方法同样需要使用该链接要求。有关更多信息,请参见 Demand vs. LinkDemand

示例

下面的示例生成 CS0688。若要解决此警告但不修改基类,请从重写方法中移除安全属性。这不能解决安全问题。

 复制代码
// 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()
    {
    }
}