PEVerify: Value class has neither fields nor size parameter

81 views
Skip to first unread message

Kenneth Skovhede

unread,
Jul 22, 2011, 2:28:54 AM7/22/11
to mono-...@googlegroups.com
When I emit a struct that has no fields, only functions, everything seems to work,
but PEVerify gives an error: 

[MD]: Error: Value class has neither fields nor size parameter. [token:0x02000002]

I have been looking for some way to set the "size parameter" but can't find it.

Is there any way I can make the error to go away, besides adding a dummy field?

Regards, Kenneth

Alex

unread,
Jul 22, 2011, 4:29:35 AM7/22/11
to mono-...@googlegroups.com
Hi Kenneth,

Try setting TypeDef.ClassSize. The default for this property probably
won't work in your case.

Regards,
Alex

> --
> --
> mono-cecil

Kenneth Skovhede

unread,
Jul 22, 2011, 11:32:17 AM7/22/11
to mono-...@googlegroups.com
Thanks, after setting ClassSize = 0 I get:
[MD]: Error: Value class has neither fields nor size parameter. [token:0x02000002]
[MD]: Error: ClassLayout has invalid PackingSize; valid set of values is {1,2,4,...,128} (parent: 0x02000002; PackingSize: 65535). [token:0x00000001]

Setting PackagingSize = 0 removes the second error, but PEVerify still complains about with:
[MD]: Error: Value class has neither fields nor size parameter. [token:0x02000002]

I'm guessing that size=0 is not allowed, even for a struct with no data,
or being handled incorrectly by the Cecil emitter.

My fix is to locally set:
type.ClassSize = type.PackingSize = (short)System.Runtime.InteropServices.Marshal.SizeOf(typeof(IntPtr));

I'm not sure how much overhead this will cause, but presumably this will take up 4/8 bytes of stack space for each call.

Regards, Kenneth

Gábor Kozár

unread,
Jul 22, 2011, 12:17:44 PM7/22/11
to mono-...@googlegroups.com
As far as I know, the minimum size of an object is 4 bytes (the size of a plain System.Object value). You could try setting it to that value, and see if PEVerify still complains.

2011/7/22 Kenneth Skovhede <ken...@hexad.dk>
--
--
mono-cecil

Reply all
Reply to author
Forward
0 new messages