Marshalling is medium or
gateway to communicate with an unmanaged code from managed code in better way
and vice versa, by using pinvoke, and ensures that data is returned back in a
safe manner.
It is one of the core services
offered by CLR (Common Language Runtime).
Because most of types in
unmanaged environment do not have counterparts in managed environment, so we
have to create conversion routine that convert manage types into unmanaged
types and vice versa.
We call .Net code “Managed
code” because it is controlled by CLR. Other code that is not managed by the
CLR is called as unmanaged code.