Possible Duplicate:
Is the class NativeMethods handled specially in .NET?
I'm working on a C# project that pinvokes some unmanaged C++ code for some functionality. I found out about fxCop and it complained about the way I included the functions from the unmanaged library.
It suggest using one of the NativeMethods classes which are explained here:
http://msdn.microsoft.com/en-us/library/ms182161%28v=vs.80%29.aspx
I read it but I can't say I understood what it exactly does and what will be the benefit of using it. I'd be really happy if someone could explain me the meaning of "This class does not suppress stack walks for unmanaged code permission." and "This class suppresses stack walks for unmanaged code permission."
Edit: What I really wonder is how it affects my code. I've read what it says on MSDN, and obviously it's enough knowledge for some people but it's too high for me to understand. That's why I asked for some elaborations.
The Visual Studio 2012 version of this article contains more explanation,
http://msdn.microsoft.com/en-us/library/ms182161(v=vs.110).aspx
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 that are called SafeNativeMethods and UnsafeNativeMethods. These classes resemble the NativeMethods class; however, they are marked by using 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, It also enables code that has limited permissions to call these methods.
However, you should use this attribute with great care. It can have serious security implications if it is implemented incorrectly..
For information about how to implement the methods, see the NativeMethods Example, SafeNativeMethods Example, and UnsafeNativeMethods Example.