Marshaling
This is the utility and process to ensure that data is passed in correct formats. As mobility-transfer enabler of sorts, this is a process and function, similar to serialization. For the most part, marshalling is the process of transforming the memory representation of an object, to a data format. One which is most/best-suitable for storage or transmission.
It is widely and typically used when data must be moved between different parts of a computer program, or from one program to another. Unmarshalling (also known as deserialization, for the reverse or opposite.
It is all about taking and having, giving, control, formatting parameters for use by COM. When there is a data transfer between multiple threads for example, conversions unmanaged type and CLR type P/Invoke process, scripts and XPCOM (firefox browser), XPConnect.
COM (Component, Object Model) .NET types, controlling marshalling, enabling interoperability, data transfer dynamics and success, data integrity and security are all by-products in, from and of these processes.
Review the chapters on inter-operating with COM using.NET types for COM applications (exposure and use, visa versa), using the DLLImport attribute between COM and .NET, for conversion-defaults or custom that do not work, or give the desired result, controlling in essence then the aspects that matter form the external function call. This is used then to provide a similar character where no exact match really exists. Take note of best-fit mapping Unicode/ANSI characters, CallingConvention WINAPI, Charset, for string parameters, entrypoint, exactspelling preserveSig, SetLastError, ThrowOnUnmappableChar.
The Marshal class can be used as a static class of interoperability utilities. MarshalGetLastWin32Error, integer representing the last occurred error. Another example is Marshal.SizeOf, Copy, GenerateGuidForType, GenerateProdIDForType, exceptions HRESULT Error codes, exceptions etc. Also handy to know is how to override the default marshalling settings, or controlling it manually, using the MarshalAs attribute.
Key Exam Points
- Use Marshaling processes, function and programming, for improved performance and security, review the chapter on Interoperability, COM.
- For the exam, study examples for marshaling commands, code, usage and applications in real-life, illustrative, practical, hands-on, lab and practice exercises, that help you to gain a better step-by-step understanding of this topic
- Take the practice test, with sample Q & A pertaining to Marshaling specific (multiple-choice), et al.
Related Terms
COM, Type Library
This article is based on the 2nd edition of the Microsoft .Net Framework Application Training Kit with the purpose to help 70-536 Exam takers to succeed. I constantly look for ways to improve the content. Please leave a comment about this article or drop me a message if you would like to see changes for this site.





