CS.SV.TRANSP.CONFLICT

メンバーには競合している透過的な注釈があってはなりません。

透過性属性は、より大きなスコープのコード要素からより小さなスコープの要素に適用されます。スコープがより大きなコード要素の透過性属性は、最初の要素に含まれているコード要素の透過性属性よりも優先されます。たとえば、SecurityCriticalAttribute 属性でマークされたクラスには、SecuritySafeCriticalAttribute 属性でマークされたメソッドを含めることはできません。

軽減と防止

この違反を修正するには、より低いスコープのコード要素からセキュリティ属性を削除するか、含んでいるコード要素と同じになるようにその属性を変更します。

脆弱コード例

コピー
  using System;
  using System.Security;
  
  namespace TransparencyWarningsDemo
  {
  
      [SecurityCritical]
      public class CriticalClass
     {
         // CA2136 violation - this method is not really safe critical, since the larger scoped type annotation 
         // has precidence over the smaller scoped method annotation.  This can be fixed by removing the 
         // SecuritySafeCritical attribute on this method
         [SecuritySafeCritical]
         public void SafeCriticalMethod()
         {
         }
     }
 }

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