Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

Type link demands require inheritance demands

TypeName

TypeLinkDemandsRequireInheritanceDemands

CheckId

CA2126

Category

Microsoft.Security

Breaking Change

Breaking

A public unsealed type is protected with a link demand, has an overridable method, and neither the type nor the method is protected with an inheritance demand.

A link demand on a method or its declaring type requires the immediate caller of the method to have the specified permission. An inheritance demand on a method requires an overriding method to have the specified permission. An inheritance demand on a type requires a deriving class to have the specified permission.

To fix a violation of this rule, secure the type or the method with an inheritance demand for the same permission as the link demand.

Do not exclude a warning from this rule.

The following example shows a type that violates the rule.

using namespace System;
using namespace System::Security::Permissions;

namespace SecurityLibrary
{
    [EnvironmentPermission(SecurityAction::LinkDemand, Read = "PATH")]
    public ref class TypesWithLinkDemands
    {
    protected:
        virtual void UnsecuredMethod() {}

        [EnvironmentPermission(SecurityAction::InheritanceDemand, 
           Read = "PATH")]
        virtual void SecuredMethod() {}
    };
}

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.