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 ()
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:

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.

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.

Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

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.