次の方法で共有


CA2135: レベル 2 のアセンブリは LinkDemand を含んではならない

TypeName

SecurityRuleSetLevel2MethodsShouldNotBeProtectedWithLinkDemands

CheckId

CA2135

[カテゴリ]

Microsoft.Security

互換性に影響する変更点

あり

原因

クラスまたはクラスのメンバーが、レベル 2 のセキュリティを使用するアプリケーションで LinkDemand を使用しています。

規則の説明

LinkDemands は、レベル 2 のセキュリティ規則セットでは使用が推奨されていません。LinkDemands を使用して Just-In-Time (JIT) コンパイル時にセキュリティを適用するのではなく、メソッド、型、およびフィールドに SecurityCriticalAttribute 属性を設定します。

違反の修正方法

この規則違反を修正するには、LinkDemand 属性を削除し、型またはメンバーに SecurityCriticalAttribute 属性を設定します。

警告を抑制する状況

この規則による警告は抑制しないでください。

使用例

次の例では、LinkDemand を削除し、メソッドに SecurityCriticalAttribute 属性を設定する必要があります。

using System;
using System.Security;
using System.Security.Permissions;

namespace TransparencyWarningsDemo
{

    public class MethodsProtectedWithLinkDemandsClass
    {
        // CA2135 violation - the LinkDemand should be removed, and the method marked [SecurityCritical] instead
        [SecurityPermission(SecurityAction.LinkDemand, UnmanagedCode = true)]
        public void ProtectedMethod()
        {
        }
    }
}