Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Compiler Error CS0636
Collapse the table of content
Expand the table of content

Compiler Error CS0636

The FieldOffset attribute can only be placed on members of types marked with the StructLayout(LayoutKind.Explicit)

You must use the StructLayout(LayoutKind.Explicit) attribute on the struct declaration, if it contains any members marked with the FieldOffset attribute. For more information, see FieldOffset.

The following sample generates CS0636:

// CS0636.cs
using System;
using System.Runtime.InteropServices;

// To resolve the error, uncomment the following line:
// [StructLayout(LayoutKind.Explicit)]
struct Worksheet
{
   [FieldOffset(4)]public int i;   // CS0636 
}

public class MainClass
{
   public static void Main ()
   {
   }
}

Community Additions

ADD
Show:
© 2015 Microsoft