Bug 25059

Summary: StructLayout.Pack >= 16 throws TypeLoadException at runtime
Product: [Mono] Runtime Reporter: Jared <jared.deckard>
Component: JITAssignee: Bugzilla <bugzilla>
Status: RESOLVED FIXED    
Severity: normal CC: mono-bugs+mono, mono-bugs+runtime, vargaz
Priority: ---    
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Linux   
Tags: 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.

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.