I've tried to compile .NET project and this CA appears, however I can't find any information about it on MSDN, do you know how to fix it?
-
1Add `[SecurityCritical]` to the field, and perhaps the containing type. – SLaks Jun 17 '13 at 15:15
-
I googled for CA2151 and found it at once - https://msdn.microsoft.com/en-us/library/dn621098.aspx - what is the question here? – Lasse V. Karlsen Nov 18 '16 at 14:11
2 Answers
The documentation can be found here:
Rule Description
To use security critical types, the code that references the type must be either security critical or security safe critical. This is true even if the reference is indirect. For example, when you reference a transparent field that has a critical type, your code must be either security critical or security safe. Therefore, having a security transparent or security safe critical field is misleading because transparent code will still be unable to access the field.
How to Fix Violations
To fix a violation of this rule, mark the field with the SecurityCriticalAttribute
attribute, or make the type that is referenced by the field with security transparent or safe critical.

- 106,458
- 22
- 256
- 341
In the Error List you can click the underlines CA2151 link or right click the line and select Show Error Help
. Both actions will launch the MSDN overview of code analysis violations. From here you can find a link to the description of CA2151 and how to fix it.

- 4,362
- 3
- 27
- 43