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

Tags:
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:
Status:
RESOLVED FIXED

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.

Repro:
<pre>
[StructLayout(LayoutKind.Sequential, Pack = 64)]
struct s
{
    public byte test;
}
</pre>

Error:
<pre>
System.TypeLoadException : Could not load type 's' from assembly 'ProjectName, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'.
</pre>
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.