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 |
|
mikejo5000 |
mikejo |
mijacobs |
code-analysis |
vs-2019 |
Item | Value |
---|---|
RuleId | CA2149 |
Category | Microsoft.Security |
Breaking change | Breaking |
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.
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.
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.
Do not suppress a warning from this rule.
:::code language="csharp" source="../snippets/csharp/VS_Snippets_CodeAnalysis/fxcop.security.ca2149.transparentmethodsmustnotcallnativecode/cs/ca2149-transparentmethodsmustnotcallnativecode.cs" id="Snippet1":::