Skip to content

Latest commit

 

History

History
44 lines (31 loc) · 1.56 KB

ca2149.md

File metadata and controls

44 lines (31 loc) · 1.56 KB
title description ms.date ms.topic f1_keywords author ms.author manager ms.subservice monikerRange
CA2149: Transparent methods must not call into native code
A method calls a native function through a method stub such as P/Invoke.
11/04/2016
reference
CA2149
mikejo5000
mikejo
mijacobs
code-analysis
vs-2019

CA2149: Transparent methods must not call into native code

Item Value
RuleId CA2149
Category Microsoft.Security
Breaking change Breaking

Cause

A method calls a native function through a method stub such as P/Invoke.

Note

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

Rule description

This rule fires on any transparent method that calls directly into native code, for example, through a P/Invoke. Violations of this rule lead to a xref:System.MethodAccessException in the level 2 transparency model, and a full demand for xref:System.Security.Permissions.SecurityPermissionAttribute.UnmanagedCode%2A in the level 1 transparency model.

How to fix violations

To fix a violation of this rule, mark the method that calls the native code with the xref:System.Security.SecurityCriticalAttribute or xref:System.Security.SecuritySafeCriticalAttribute attribute.

When to suppress warnings

Do not suppress a warning from this rule.

Example

:::code language="csharp" source="../snippets/csharp/VS_Snippets_CodeAnalysis/fxcop.security.ca2149.transparentmethodsmustnotcallnativecode/cs/ca2149-transparentmethodsmustnotcallnativecode.cs" id="Snippet1":::