C# Error
CS0636 – The FieldOffset attribute can only be placed on members of types marked with the StructLayout(LayoutKind.Explicit)
Reason for the Error & Solution
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 .
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 ()
{
}
}