To fix a violation of this rule, move the method to the appropriate NativeMethods class. For most applications, moving P/Invokes to a new class that is named NativeMethods is enough.
However, if you are developing libraries for use in other applications, you should consider defining two other classes called SafeNativeMethods and UnsafeNativeMethods. These classes resemble the NativeMethods class, however, they are marked with a special attribute called SuppressUnmanagedCodeSecurityAttribute. When this attribute is applied, the runtime does not perform a full stack walk to make sure that all callers have the UnmanagedCode permission. The runtime ordinarily checks for this permission at startup. Because the check is not performed, it can greatly improve performance for calls to these unmanaged methods, and it also allows code with limited permissions to call these methods.
However, you should use this attribute with great care, because, implemented incorrectly, it can have serious security implications.
For information about how to implement the methods, see the NativeMethods Example, SafeNativeMethods Example, and UnsafeNativeMethods Example.