共用方式為


CA2135:層級 2 組件不應該包含 LinkDemand

型別名稱

SecurityRuleSetLevel2MethodsShouldNotBeProtectedWithLinkDemands

CheckId

CA2135

分類

Microsoft.Security

中斷變更

中斷

原因

類別或類別成員在使用層級 2 安全性的應用程式中使用 LinkDemand

規則描述

在層級 2 安全性規則集中,LinkDemand 已被取代。 不使用 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()
        {
        }
    }
}