Bug 4510 - Marshal.SizeOf returning different sizes for StructLayout(Explicit) vs. StructLayout(Sequential)
Summary: Marshal.SizeOf returning different sizes for StructLayout(Explicit) vs. Struc...
Status: RESOLVED FIXED
Alias: None
Product: Runtime
Classification: Mono
Component: General (show other bugs)
Version: unspecified
Hardware: PC Mac OS
: High normal
Target Milestone: ---
Assignee: Paolo Molaro
URL:
Depends on:
Blocks:
 
Reported: 2012-04-18 16:31 UTC by Eric Beisecker
Modified: 2014-07-30 08:44 UTC (History)
4 users (show)

See Also:
Tags:
Is this bug a regression?: ---
Last known good build:


Attachments

Description Eric Beisecker 2012-04-18 16:31:23 UTC
Example:

[StructLayout(LayoutKind.Explicit)]
struct A
{
  [FieldOffset(0)]
  int one;
  [FieldOffset(4)]
  int two;
  [FieldOffset(8)]
  int three;
}

[StructLayout(LayoutKind.Sequential)]
struct B
{
  int one;
  int two;
  int three;
}

Console.WriteLine(Marshal.SizeOf(new A())); // Will return 16
Console.WriteLine(Marshal.SizeOf(new B())); // Will return 12

Using the .NET library both examples Return 12.
Comment 1 Rodrigo Kumpera 2014-01-22 16:52:09 UTC
Fixed in master.

Note You need to log in before you can comment on or make changes to this bug.