Export (0) Print
Expand All
Expand Minimize

Compiler Warning (level 1) CS0688 

Error Message

'method1' has a link demand, but overrides or implements 'method2' which does not have a link demand. A security hole may exist.

The link demand set up on the derived class method can easily be circumvented by calling the base class method. To close the security hole, the base class method needs to also use the link demand. For more information, see Demand vs. LinkDemand.

Example

The following sample generates CS0688. To resolve the warning without modifying the base class, remove the security attribute from the overriding method. This will not solve the security problem.

// 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()
    {
    }
}

Community Additions

ADD
Show:
© 2014 Microsoft