EllanJiang/GameFramework · error · GameFrameworkException

Data bytes is invalid.

Error message

Data bytes is invalid.

What it means

The ParseData(byte[]) overload validates the byte array is non-null before forwarding to ParseData(byte[], int, int, object). A null array cannot be parsed, so it throws immediately. This is the byte-array analogue of the 'Data string is invalid.' check.

Solutions

  1. Ensure the byte array is loaded and non-null before calling ParseData.
  2. Fix the upstream load (file/network/resource) that produced a null buffer.
  3. Guard with a null check and report a load failure instead of parsing.

Example fix

// before
byte[] bytes = LoadBytes(); // null on failure
bool ok = dataProvider.ParseData(bytes);
// after
byte[] bytes = LoadBytes();
if (bytes != null && bytes.Length > 0) { bool ok = dataProvider.ParseData(bytes); }
Defensive patterns

Strategy: validation

Validate before calling

if (dataBytes == null || dataBytes.Length == 0) { /* handle missing bytes */ }
bool ok = dataProvider.ParseData(dataBytes);

Type guard

bool IsParseable(byte[] b) => b != null && b.Length > 0;

Try / catch

try { dataProvider.ParseData(bytes); }
catch (GameFrameworkException e) when (e.Message == "Data bytes is invalid.") { Log.Error("Byte buffer was null; check upstream load."); }

Prevention

When it happens

Trigger: Calling ParseData((byte[])null) — typically when a download/file read produced a null buffer and the result was passed straight into ParseData.

Common situations: WebRequest or file read failure returning null bytes; a field that was never assigned; test code probing null handling.

Related errors


AI-assisted analysis of EllanJiang/GameFramework@d0c010b051 (2026-09-15). Data as JSON: /api/errors/99da9c5c6cdbe237. Report an issue: GitHub.

Appendix: source

Thrown at GameFramework/Base/DataProvider/DataProvider.cs:300

                if (exception is GameFrameworkException)
                {
                    throw;
                }

                throw new GameFrameworkException(Utility.Text.Format("Can not parse data string with exception '{0}'.", exception), exception);
            }
        }

        /// <summary>
        /// 解析内容。
        /// </summary>
        /// <param name="dataBytes">要解析的内容二进制流。</param>
        /// <returns>是否解析内容成功。</returns>
        public bool ParseData(byte[] dataBytes)
        {
            if (dataBytes == null)
            {
                throw new GameFrameworkException("Data bytes is invalid.");
            }

            return ParseData(dataBytes, 0, dataBytes.Length, null);
        }

        /// <summary>
        /// 解析内容。
        /// </summary>
        /// <param name="dataBytes">要解析的内容二进制流。</param>
        /// <param name="userData">用户自定义数据。</param>
        /// <returns>是否解析内容成功。</returns>
        public bool ParseData(byte[] dataBytes, object userData)
        {
            if (dataBytes == null)
            {
                throw new GameFrameworkException("Data bytes is invalid.");
            }

View on GitHub (pinned to d0c010b051)