{"record":{"id":"f2b81c0ce7be83da","repo":"EllanJiang/GameFramework","slug":"no-serialize-callback-registered","errorCode":null,"errorMessage":"No serialize callback registered.","messagePattern":"No serialize callback registered\\.","errorType":"exception","errorClass":"GameFrameworkException","httpStatus":null,"severity":"error","filePath":"GameFramework/Base/GameFrameworkSerializer.cs","lineNumber":118,"sourceCode":"            if (callback == null)\n            {\n                throw new GameFrameworkException(\"Try get value callback is invalid.\");\n            }\n\n            m_TryGetValueCallbacks[version] = callback;\n        }\n\n        /// <summary>\n        /// 序列化数据到目标流中。\n        /// </summary>\n        /// <param name=\"stream\">目标流。</param>\n        /// <param name=\"data\">要序列化的数据。</param>\n        /// <returns>是否序列化数据成功。</returns>\n        public bool Serialize(Stream stream, T data)\n        {\n            if (m_SerializeCallbacks.Count <= 0)\n            {\n                throw new GameFrameworkException(\"No serialize callback registered.\");\n            }\n\n            return Serialize(stream, data, m_LatestSerializeCallbackVersion);\n        }\n\n        /// <summary>\n        /// 序列化数据到目标流中。\n        /// </summary>\n        /// <param name=\"stream\">目标流。</param>\n        /// <param name=\"data\">要序列化的数据。</param>\n        /// <param name=\"version\">序列化回调函数的版本。</param>\n        /// <returns>是否序列化数据成功。</returns>\n        public bool Serialize(Stream stream, T data, byte version)\n        {\n            byte[] header = GetHeader();\n            stream.WriteByte(header[0]);\n            stream.WriteByte(header[1]);\n            stream.WriteByte(header[2]);","sourceCodeStart":100,"sourceCodeEnd":136,"githubUrl":"https://github.com/EllanJiang/GameFramework/blob/d0c010b05167c58e92350449d04864a91ca13fd2/GameFramework/Base/GameFrameworkSerializer.cs#L100-L136","documentation":"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.","triggerScenarios":"Calling serializer.Serialize(stream, data) before any RegisterSerializeCallback call was made, or on a serializer instance that was re-created without re-registering callbacks.","commonSituations":"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.","solutions":["Register at least one serialize callback via RegisterSerializeCallback(version, callback) before serializing.","Verify you are using the fully-initialized serializer instance (not a fresh default-constructed one).","Move callback registration to startup code that is guaranteed to run before any save/serialize.","Check m_SerializeCallbacks.Count (or wrap in try-catch) before calling the versionless Serialize overload."],"exampleFix":"// before\nvar serializer = new GameFrameworkSerializer<PlayerData>();\nserializer.Serialize(stream, playerData); // no callbacks registered\n// after\nvar serializer = new GameFrameworkSerializer<PlayerData>();\nserializer.RegisterSerializeCallback(1, SerializePlayerDataV1);\nserializer.RegisterDeserializeCallback(1, DeserializePlayerDataV1);\nserializer.Serialize(stream, playerData);","handlingStrategy":"validation","validationCode":"if (serializer == null) { throw new InvalidOperationException(\"Serializer not initialized.\"); }\n// ensure registration ran: bootstrap.RegisterSerializerCallbacks(serializer);","typeGuard":"static bool IsReady<T>(GameFrameworkSerializer<T> s) => s != null; // plus your own registration-done flag","tryCatchPattern":"try { serializer.Serialize(stream, data); } catch (GameFrameworkException ex) { log.Error(\"Serializer not initialized: \" + ex.Message); }","preventionTips":["Register callbacks immediately after constructing the serializer","Route all serializer creation through a single bootstrap","Never serialize from code paths that may run before registration (e.g. Awake order issues)"],"tags":["csharp","missing-registration","serialization","init-order"],"backgroundTag":"missing-dependency","analyzedSha":"d0c010b05167c58e92350449d04864a91ca13fd2","analyzedAt":"2026-09-15T13:37:15.352Z","contentChangedAt":"2026-09-15T13:37:15.352Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}