Bug 25059 - StructLayout.Pack >= 16 throws TypeLoadException at runtime
Summary: StructLayout.Pack >= 16 throws TypeLoadException at runtime
Alias: None
Product: Runtime
Classification: Mono
Component: JIT (show other bugs)
Version: unspecified
Hardware: PC Linux
: --- normal
Target Milestone: ---
Assignee: Bugzilla
Depends on:
Reported: 2014-12-04 00:07 UTC by Jared
Modified: 2014-12-09 15:40 UTC (History)
3 users (show)

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


Description Jared 2014-12-04 00:07:55 UTC
When the Pack property of the StructLayout attribute is greater than or equal to 16, the struct definition is ignored, the build succeeds without warning, and throws TypeLoadException at runtime.

C# .NET silently falls back to the default Pack value.

It would be nice if mono would fall back to the default value and produce a build warning. At the very least if the struct definition is going be ignored entirely it should produce a build warning or error.

[StructLayout(LayoutKind.Sequential, Pack = 64)]
struct s
    public byte test;

System.TypeLoadException : Could not load type 's' from assembly 'ProjectName, Version=, Culture=neutral, PublicKeyToken=null'.
Comment 1 Marek Safar 2014-12-04 08:52:58 UTC
Same code work on .net

using System.Runtime.InteropServices;

[StructLayout(LayoutKind.Sequential, Pack = 64)]
struct s
    public byte test;

class X
	public static void Main ()
		s _s = new s ();
Comment 2 Zoltan Varga 2014-12-09 15:40:26 UTC
Fixed in master.

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Create a new report for Bug 25059 on Developer Community or GitHub if you have new information to add and do not yet see a matching report.

  • Export the original title and description: Developer Community HTML or GitHub Markdown
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Related Links: