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 ()
{
}
}
Collaborate with us on GitHub
The source for this content can be found on GitHub, where you can also create and review issues and pull requests. For more information, see our contributor guide.
.NET feedback
.NET is an open source project. Select a link to provide feedback: