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)

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


Attachments

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.

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