In most cases, the runtime can automatically determine how data is marshaled between native and managed code, so you usually don't need to specify an attribute. MarshalAsnecessary only in case of uncertainty in the definition (and you want to specify the runtime exactly, as for data marshaling), or if you require non-standard behavior.
In my experience, it is MarshalAsreally only required when working with strings, since there are so many different representations in the native code; unicode / ansi, c-lines or not, etc.
source
share