EllanJiang/GameFramework · error · GameFrameworkException
Code length is invalid.
Error message
Code length is invalid.
What it means
Utility.GetCrc32 throws GameFrameworkException with 'Code length is invalid.' when the byte[] code parameter has zero length. The code array seeds the CRC32 computation and must contain at least one byte; an empty array yields no usable seed.
Solutions
- Pass a code array with at least 1 byte (standard CRC32 uses a 4-byte seed).
- Validate code.Length > 0 before calling, or default to a 4-byte seed.
- Fix the producer of the empty array (file read, network payload, config).
Example fix
// before
byte[] code = new byte[0];
int crc = Utility.Verifier.GetCrc32(stream, code, length);
// after
byte[] code = codeBytes != null && codeBytes.Length > 0 ? codeBytes : new byte[] { 0, 0, 0, 0 };
int crc = Utility.Verifier.GetCrc32(stream, code, length); Defensive patterns
Strategy: validation
Validate before calling
if (code != null && code.Length > 0)
{
int crc = Utility.Verifier.GetCrc32(stream, code, length);
} Type guard
bool IsValidCrcSeed(byte[] code) => code != null && code.Length > 0;
Try / catch
try
{
int crc = Utility.Verifier.GetCrc32(stream, code, length);
}
catch (GameFrameworkException ex) when (ex.Message.Contains("Code length"))
{
crc = Utility.Verifier.GetCrc32(stream, DefaultCrcSeed, 0); // fall back to default seed
} Prevention
- Standardize on a 4-byte CRC seed constant for the project.
- Validate arrays returned by file/network reads before using them as seeds.
- Unit-test any helper that produces the seed array for the empty case.
When it happens
Trigger: Calling Utility.Verifier.GetCrc32(stream, code, length) with code being a non-null but empty (Length == 0) byte array.
Common situations: code = new byte[0] created by a failed allocation or an empty file read; a seed loaded from a zero-byte file; an array produced by an empty serialization result.
Understand the failure class
Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.
Related errors
- Code is invalid.
- Owner is invalid.
- Resource manager is invalid.
- Data provider helper is invalid.
- Type is invalid.
AI-assisted analysis of EllanJiang/GameFramework@d0c010b051 (2026-09-15).
Data as JSON: /api/errors/df7d2a35c3a5aba6.
Report an issue: GitHub.
Appendix: source
Thrown at GameFramework/Utility/Utility.Verifier.cs:154
bytes[offset + 3] = (byte)(crc32 & 0xff);
}
internal static int GetCrc32(Stream stream, byte[] code, int length)
{
if (stream == null)
{
throw new GameFrameworkException("Stream is invalid.");
}
if (code == null)
{
throw new GameFrameworkException("Code is invalid.");
}
int codeLength = code.Length;
if (codeLength <= 0)
{
throw new GameFrameworkException("Code length is invalid.");
}
int bytesLength = (int)stream.Length;
if (length < 0 || length > bytesLength)
{
length = bytesLength;
}
int codeIndex = 0;
while (true)
{
int bytesRead = stream.Read(s_CachedBytes, 0, CachedBytesLength);
if (bytesRead > 0)
{
if (length > 0)
{
for (int i = 0; i < bytesRead && i < length; i++)
{View on GitHub (pinned to d0c010b051)