SDT0607: Missing or Invalid StructLayout
| Property | Value |
|---|---|
| Rule ID | SDT0607 |
| Title | Missing or Invalid StructLayout |
| Category | Network |
| Severity | Error |
Cause
A custom struct passed as an argument in an [RPC] method lacks a explicit [StructLayout] attribute, uses LayoutKind.Auto, or defines a total byte Size of 0.
Rule Description
For fast blitting and zero-allocation binary network transport, custom structs used in network payloads must have a fixed, deterministic memory layout (LayoutKind.Sequential or LayoutKind.Explicit) with an explicitly defined size.
How to Fix Violations
Decorate the target struct definition with a explicit [StructLayout] specifying a non-auto layout and an exact byte size.
Violation:
public struct NetworkVector
{
public float X;
public float Y;
}
Fix:
using System.Runtime.InteropServices;
// ...
[StructLayout(LayoutKind.Sequential, Size = 8)]
public struct NetworkVector
{
public float X;
public float Y;
}
When to Suppress Warnings
Danger
Do not suppress this error. Managed memory layouts are volatile; without a pinned native struct layout, data serialization corruption will occur across different CPU architectures.