stride3d/stride · error · InvalidOperationException
Unexpected type [ ] to add while serializable types are…
Error message
Unexpected type [{0}] to add while serializable types are frozen What it means
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.
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
Example fix
// before // custom processor step run after serialization codegen started context.ResolveSerializer(myType); // frozen // after // run resolution during ProcessSerializers attribute-scan phase, before code generation ScanSerializers(context, myType);
Defensive patterns
Strategy: validation
Validate before calling
// Resolve all serializers during the scan phase; assert none are pending at codegen time:
if (profile.IsFrozen && pendingTypes.Count > 0)
throw new InvalidOperationException("Late serializer registrations: " + string.Join(",", pendingTypes)); Try / catch
try { context.AddSerializableType(type, info); }
catch (InvalidOperationException ex) when (ex.Message.Contains("frozen"))
{
logger.Warn($"Type {type} registered too late; move registration before codegen");
} Prevention
- 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
When it happens
Trigger: AddSerializableType (via any serializer resolution path) tries to register a new non-generic SerializableTypeInfo after the processor froze the profile's type list.
Common situations: 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.
Understand the failure class
Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.
Related errors
- A session is already open in this instance.
- Aliases are not supported in JSON
- At least one profile must be specified.
- Attributes can not be null
- Can't deduce data serializer type for generic types.
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/0bbca590b25dafbf.
Report an issue: GitHub.
Appendix: source
Thrown at sources/core/Stride.Core.AssemblyProcessor/Serializers/CecilSerializerContext.cs:608
public bool TryGetSerializableTypeInfo(TypeReference type, bool generic, out SerializableTypeInfo result)
{
return generic
? GenericSerializableTypes.TryGetValue(type, out result)
: SerializableTypes.TryGetValue(type, out result);
}
public void AddSerializableTypeInfo(TypeReference typeReference, SerializableTypeInfo serializableTypeInfo)
{
if (serializableTypeInfo.Mode != DataSerializerGenericMode.None)
{
GenericSerializableTypes.Add(typeReference, serializableTypeInfo);
}
else
{
if (IsFrozen)
{
throw new InvalidOperationException(string.Format("Unexpected type [{0}] to add while serializable types are frozen", typeReference));
}
SerializableTypes.Add(typeReference, serializableTypeInfo);
}
}
}
}
View on GitHub (pinned to 96fad776d2)