EllanJiang/GameFramework · error · GameFrameworkException

No serialize callback registered.

Error message

No serialize callback registered.

What it means

The parameterless-version Serialize(stream, data) delegates to Serialize with m_LatestSerializeCallbackVersion. It throws when no serialize callbacks have been registered at all (m_SerializeCallbacks.Count <= 0), because there would be no way to encode the data and the latest-version lookup would be meaningless.

Solutions

  1. Register at least one serialize callback via RegisterSerializeCallback(version, callback) before serializing.
  2. Verify you are using the fully-initialized serializer instance (not a fresh default-constructed one).
  3. Move callback registration to startup code that is guaranteed to run before any save/serialize.
  4. Check m_SerializeCallbacks.Count (or wrap in try-catch) before calling the versionless Serialize overload.

Example fix

// before
var serializer = new GameFrameworkSerializer<PlayerData>();
serializer.Serialize(stream, playerData); // no callbacks registered
// after
var serializer = new GameFrameworkSerializer<PlayerData>();
serializer.RegisterSerializeCallback(1, SerializePlayerDataV1);
serializer.RegisterDeserializeCallback(1, DeserializePlayerDataV1);
serializer.Serialize(stream, playerData);
Defensive patterns

Strategy: validation

Validate before calling

if (serializer == null) { throw new InvalidOperationException("Serializer not initialized."); }
// ensure registration ran: bootstrap.RegisterSerializerCallbacks(serializer);

Type guard

static bool IsReady<T>(GameFrameworkSerializer<T> s) => s != null; // plus your own registration-done flag

Try / catch

try { serializer.Serialize(stream, data); } catch (GameFrameworkException ex) { log.Error("Serializer not initialized: " + ex.Message); }

Prevention

When it happens

Trigger: Calling serializer.Serialize(stream, data) before any RegisterSerializeCallback call was made, or on a serializer instance that was re-created without re-registering callbacks.

Common situations: Instantiating GameFrameworkSerializer<T> manually instead of through the registration/bootstrap code path; initialization order issues where save happens before callback registration; a version-upgrade path that registers callbacks only behind a flag.

Understand the failure class

Background: "not installed", "pip install", "required for": how missing-dependency errors surface across open-source libraries — this error's family across 34 libraries.

Related errors


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

Appendix: source

Thrown at GameFramework/Base/GameFrameworkSerializer.cs:118

            if (callback == null)
            {
                throw new GameFrameworkException("Try get value callback is invalid.");
            }

            m_TryGetValueCallbacks[version] = callback;
        }

        /// <summary>
        /// 序列化数据到目标流中。
        /// </summary>
        /// <param name="stream">目标流。</param>
        /// <param name="data">要序列化的数据。</param>
        /// <returns>是否序列化数据成功。</returns>
        public bool Serialize(Stream stream, T data)
        {
            if (m_SerializeCallbacks.Count <= 0)
            {
                throw new GameFrameworkException("No serialize callback registered.");
            }

            return Serialize(stream, data, m_LatestSerializeCallbackVersion);
        }

        /// <summary>
        /// 序列化数据到目标流中。
        /// </summary>
        /// <param name="stream">目标流。</param>
        /// <param name="data">要序列化的数据。</param>
        /// <param name="version">序列化回调函数的版本。</param>
        /// <returns>是否序列化数据成功。</returns>
        public bool Serialize(Stream stream, T data, byte version)
        {
            byte[] header = GetHeader();
            stream.WriteByte(header[0]);
            stream.WriteByte(header[1]);
            stream.WriteByte(header[2]);

View on GitHub (pinned to d0c010b051)