Marshal.SizeOf throws ArgumentException on enums
This appears to be a limitation imposed by a difference between the requirements of ECMA-335 for enums (ECMA-335 Partition II §14.3):
...they shall have auto field layout (§10.1.2); ...
And the expectations of Marshal.SizeOf
:
You can use this method when you do not have a structure. The layout must be sequential or explicit.
Based on this, you will need to use Enum.GetUnderlyingType
before calling Marshal.SizeOf
.