{"record":{"id":"0bbca590b25dafbf","repo":"stride3d/stride","slug":"unexpected-type-0-to-add-while-serializable-types-are-frozen","errorCode":null,"errorMessage":"Unexpected type [{0}] to add while serializable types are frozen","messagePattern":"Unexpected type \\[(.+?)\\] to add while serializable types are frozen","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"sources/core/Stride.Core.AssemblyProcessor/Serializers/CecilSerializerContext.cs","lineNumber":608,"sourceCode":"\n        public bool TryGetSerializableTypeInfo(TypeReference type, bool generic, out SerializableTypeInfo result)\n        {\n            return generic\n                ? GenericSerializableTypes.TryGetValue(type, out result)\n                : SerializableTypes.TryGetValue(type, out result);\n        }\n\n        public void AddSerializableTypeInfo(TypeReference typeReference, SerializableTypeInfo serializableTypeInfo)\n        {\n            if (serializableTypeInfo.Mode != DataSerializerGenericMode.None)\n            {\n                GenericSerializableTypes.Add(typeReference, serializableTypeInfo);\n            }\n            else\n            {\n                if (IsFrozen)\n                {\n                    throw new InvalidOperationException(string.Format(\"Unexpected type [{0}] to add while serializable types are frozen\", typeReference));\n                }\n                SerializableTypes.Add(typeReference, serializableTypeInfo);\n            }\n        }\n    }\n}\n","sourceCodeStart":590,"sourceCodeEnd":615,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/core/Stride.Core.AssemblyProcessor/Serializers/CecilSerializerContext.cs#L590-L615","documentation":"ProfileInfo.Add enforces that once the serializable-type set is frozen (after initial scanning), no new non-generic types can be added. This is an internal ordering invariant: late additions would not be part of the generated serializer set.","triggerScenarios":"AddSerializableType (via any serializer resolution path) tries to register a new non-generic SerializableTypeInfo after the processor froze the profile's type list.","commonSituations":"Custom assembly-processing extensions that resolve serializers too late in the pipeline; a serializer whose resolution triggers discovery of new types after freeze; Stride source modifications changing processing order.","solutions":["Register all serializers before the freeze point (during attribute scanning, not code generation)","Pre-resolve the serializer earlier so the type is added before IsFrozen is set","If writing a processor extension, hook into the scanning phase rather than the generation phase","In Stride source, unfreeze only with care or extend the frozen set explicitly"],"exampleFix":"// before\n// custom processor step run after serialization codegen started\ncontext.ResolveSerializer(myType); // frozen\n// after\n// run resolution during ProcessSerializers attribute-scan phase, before code generation\nScanSerializers(context, myType);","handlingStrategy":"validation","validationCode":"// Resolve all serializers during the scan phase; assert none are pending at codegen time:\nif (profile.IsFrozen && pendingTypes.Count > 0)\n    throw new InvalidOperationException(\"Late serializer registrations: \" + string.Join(\",\", pendingTypes));","typeGuard":null,"tryCatchPattern":"try { context.AddSerializableType(type, info); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"frozen\"))\n{\n    logger.Warn($\"Type {type} registered too late; move registration before codegen\");\n}","preventionTips":["Register all serializers during attribute scanning, before code generation","Order custom processor steps before the freeze point","Never trigger new serializer resolution from code-generation hooks"],"tags":["serialization","state","pipeline-order"],"backgroundTag":"invalid-state-transition","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}