Skip to content

Latest commit

 

History

History
44 lines (31 loc) · 1.89 KB

ca2145.md

File metadata and controls

44 lines (31 loc) · 1.89 KB
title description ms.date ms.topic f1_keywords author ms.author manager ms.subservice monikerRange
CA2145: Transparent methods should not be decorated with the SuppressUnmanagedCodeSecurityAttribute
A transparent method, a method that is marked with the SecuritySafeCritical attribute, or a type that contains a method is marked with the SuppressUnmanagedCodeSecurity attribute.
11/04/2016
reference
CA2145
mikejo5000
mikejo
mijacobs
code-analysis
vs-2019

CA2145: Transparent methods should not be decorated with the SuppressUnmanagedCodeSecurityAttribute

Item Value
RuleId CA2145
Category Microsoft.Security
Breaking change Breaking

Cause

A transparent method, a method that is marked with the xref:System.Security.SecuritySafeCriticalAttribute attribute, or a type that contains a method is marked with the xref:System.Security.SuppressUnmanagedCodeSecurityAttribute attribute.

Note

This rule has been deprecated. For more information, see Deprecated rules.

Rule description

Methods decorated with the xref:System.Security.SuppressUnmanagedCodeSecurityAttribute attribute have an implicit LinkDemand placed upon any method that calls it. This LinkDemand requires that the calling code be security critical. Marking the method that uses SuppressUnmanagedCodeSecurity with the xref:System.Security.SecurityCriticalAttribute attribute makes this requirement more obvious for callers of the method.

How to fix violations

To fix a violation of this rule, mark the method or type with the xref:System.Security.SecurityCriticalAttribute attribute.

When to suppress warnings

Do not suppress a warning from this rule.

Code

:::code language="csharp" source="../snippets/csharp/VS_Snippets_CodeAnalysis/fxcop.security.ca2145.transparentmethodsshouldnotusesuppressunmanagedcodesecurity/cs/ca2145.cs" id="Snippet1":::