CS.SV.CRITICAL_LVL
Types must be at least as critical as their base types and interfaces.
This rule fires when a derived type has a security transparency attribute that is not as critical as its base type or implemented interface. Only critical types can derive from critical base types or implement critical interfaces, and only critical or safe-critical types can derive from safe-critical base types or implement safe-critical interfaces. Violations of this rule in level 2 transparency result in a TypeLoadException for the derived type.
Mitigation and prevention
To fix this violation, mark the derived or implementing type with a transparency attribute that is at least as critical as the base type or interface.
Example
2 using System; 3 using System.Security; 4 5 namespace TransparencyWarningsDemo 6 { 7 8 [SecuritySafeCritical] 9 public class SafeCriticalBase 10 { 11 } 12 13 // CA2156 violation - a transparent type cannot derive from a safe critical type. The fix is any of: 14 // 1. Make SafeCriticalBase transparent 15 // 2. Make TransparentFromSafeCritical safe critical 16 // 3. Make TransparentFromSafeCritical critical 17 public class TransparentFromSafeCritical : SafeCriticalBase 18 { 19 } 20 21 [SecurityCritical] 22 public class CriticalBase 23 { 24 } 25 26 // CA2156 violation - a transparent type cannot derive from a critical type. The fix is any of: 27 // 1. Make CriticalBase transparent 28 // 2. Make TransparentFromCritical critical 29 public class TransparentFromCritical : CriticalBase 30 { 31 } 32 33 // CA2156 violation - a safe critical type cannot derive from a critical type. The fix is any of: 34 // 1. Make CriticalBase transparent 35 // 2. Make CriticalBase safe critical 36 // 3. Make SafeCriticalFromCritical critical 37 [SecuritySafeCritical] 38 public class SafeCriticalFromCritical : CriticalBase 39 { 40 } 41 42 }