CS.SV.LINK_DEMAND.LEVEL2

レベル 2 アセンブリには LinkDemands を含めないでください。

レベル 2 セキュリティ規則セットでは、LinkDemand は廃止されています。just-in-time (JIT) コンパイル時に LinkDemands を使用してセキュリティを執行する代わりに、メソッド、型、およびフィールドを 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()
         {
         }
     }
 }

この例では、LinkDemand を削除し、SecurityCriticalAttribute 属性でメソッドをマークする必要があります。