egametang/ET · error · SerializationException
Serialization_MismatchedCount
Error message
Serialization_MismatchedCount
What it means
Thrown at the end of OnDeserialization after all items are re-Added: the live count does not match CountName from the stream. Because SortedSet deduplicates via Add, a mismatch means duplicate items were stored (impossible for a normal set) or the stream's count is wrong. Surfaces as a SerializationException (Serialization_MismatchedCount).
Source
Thrown at Packages/cn.etetet.core/Scripts/Core/Share/Collection/SortedSet.cs:1735
if (savedCount != 0)
{
T[] items = (T[])siInfo.GetValue(ItemsName, typeof(T[]));
if (items == null)
{
throw new SerializationException(SR.Serialization_MissingValues);
}
for (int i = 0; i < items.Length; i++)
{
Add(items[i]);
}
}
version = siInfo.GetInt32(VersionName);
if (count != savedCount)
{
throw new SerializationException(SR.Serialization_MismatchedCount);
}
siInfo = null;
}
#endregion
#region Helper classes
public sealed class Node
{
public Node(T item, NodeColor color)
{
Item = item;
Color = color;
}
private Node()View on GitHub (pinned to 5cab01f7a8)
Solutions
- Regenerate the persisted data from a canonical SortedSet so Count and Items stay consistent.
- Verify the comparer used at deserialize time matches the one used at serialize time.
- If you must accept untrusted streams, deserialize into a List and rebuild the set rather than trusting the stored count.
Defensive patterns
Strategy: validation
Validate before calling
// When authoring serialization, ensure Items has no duplicates and Count == distinct count: T[] arr = set.ToArray(); info.AddValue(CountName, arr.Length); info.AddValue(ItemsName, arr);
Try / catch
try { /* deserialize */ } catch (SerializationException ex) when (ex.Message.Contains("Serialization_MismatchedCount")) { /* rebuild set from raw items, ignoring stored count */ } Prevention
- Keep the comparer identical across serialize and deserialize.
- Never store duplicate items; SortedSet semantics forbid them.
- Re-derive Count from Items in custom serialization.
When it happens
Trigger: Serialized Items array contained duplicates and the comparer collapsed them (so count shrank); serialized Count was hand-set wrong; a non-strict comparer that treats distinct references as equal during rehydration.
Common situations: Data written by a buggy serializer that included duplicates; switching to an IEqualityComparer/IComparer that merges previously-distinct keys; partial re-serialization that updated Items but not Count.
Related errors
- Serialization_InvalidOnDeser
- Serialization_MissingValues
- 不支持导出 UnityEngine.Object 类型: {runtimeType.FullName}
- {runtimeType.FullName} 缺少可用于导出的公共构造函数。必须通过构造函数提供的成员: {names}
- 无法为类型 {type.FullName} 生成稳定排序键
AI-assisted analysis of egametang/ET@5cab01f7a8 (2026-08-13).
Data as JSON: /api/errors/f21091b0bdb21b89.
Report an issue: GitHub.