StructLayout Explicit and dummy fields produce compiler error
- Dominant language
- C#
- Stars
- 729
- Forks
- 397
- Avg merge
- 3d 15m
- Merged PRs (30d)
- 149
Description
When `private readonly object _dummy;` is added to a struct with `LayoutKind.Explic` it's added without `FieldOffsetAttribute` and causes a compiler error:
```
error CS0625: 'RenderTreeFrame._dummy': instance field in types marked with StructLayou t(LayoutKind.Explicit) must have a FieldOffset attribute [
```
``` C#
[System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Explicit)]
public readonly partial struct RenderTreeFrame
{
private readonly object _dummy;
[System.Runtime.InteropServices.FieldOffsetAttribute(8)]
public readonly int AttributeEventHandlerId;
[System.Runtime.InteropServices.FieldOffsetAttribute(16)]
public readonly string AttributeName;
[System.Runtime.InteropServices.FieldOffsetAttribute(24)]
public readonly object AttributeValue;
[System.Runtime.InteropServices.FieldOffsetAttribute(12)]
public readonly int ComponentId;
[System.Runtime.InteropServices.FieldOffsetAttribute(16)]
public readonly System.Action ComponentReferenceCaptureAction;
[System.Runtime.InteropServices.FieldOffsetAttribute(8)]
public readonly int ComponentReferenceCaptureParentFrameIndex;
}
```
Contributor guide
Research direction
Start by compiling the minimal C# example in the issue, focusing on the explicit-layout RenderTreeFrame struct and its _dummy field. Confirm the CS0625 diagnostic and determine which project source or generation path produces this declaration. Done means the reported compiler error is resolved without breaking the explicit field offsets.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100